VRMLLoader.js 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581
  1. /**
  2. * @author Mugen87 / https://github.com/Mugen87
  3. */
  4. /* global chevrotain */
  5. THREE.VRMLLoader = ( function () {
  6. // dependency check
  7. if ( typeof chevrotain === 'undefined' ) {
  8. throw Error( 'THREE.VRMLLoader: External library chevrotain.min.js required.' );
  9. }
  10. // class definitions
  11. function VRMLLoader( manager ) {
  12. THREE.Loader.call( this, manager );
  13. }
  14. VRMLLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype ), {
  15. constructor: VRMLLoader,
  16. load: function ( url, onLoad, onProgress, onError ) {
  17. var scope = this;
  18. var path = ( scope.path === '' ) ? THREE.LoaderUtils.extractUrlBase( url ) : scope.path;
  19. var loader = new THREE.FileLoader( this.manager );
  20. loader.setPath( scope.path );
  21. loader.load( url, function ( text ) {
  22. onLoad( scope.parse( text, path ) );
  23. }, onProgress, onError );
  24. },
  25. parse: function ( data, path ) {
  26. var nodeMap = {};
  27. function generateVRMLTree( data ) {
  28. // create lexer, parser and visitor
  29. var tokenData = createTokens();
  30. var lexer = new VRMLLexer( tokenData.tokens );
  31. var parser = new VRMLParser( tokenData.tokenVocabulary );
  32. var visitor = createVisitor( parser.getBaseCstVisitorConstructor() );
  33. // lexing
  34. var lexingResult = lexer.lex( data );
  35. parser.input = lexingResult.tokens;
  36. // parsing
  37. var cstOutput = parser.vrml();
  38. if ( parser.errors.length > 0 ) {
  39. console.error( parser.errors );
  40. throw Error( 'THREE.VRMLLoader: Parsing errors detected.' );
  41. }
  42. // actions
  43. var ast = visitor.visit( cstOutput );
  44. return ast;
  45. }
  46. function createTokens() {
  47. var createToken = chevrotain.createToken;
  48. // from http://gun.teipir.gr/VRML-amgem/spec/part1/concepts.html#SyntaxBasics
  49. var RouteIdentifier = createToken( { name: 'RouteIdentifier', pattern: /[^\x30-\x39\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d][^\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d]*[\.][^\x30-\x39\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d][^\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d]*/ } );
  50. var Identifier = createToken( { name: 'Identifier', pattern: /[^\x30-\x39\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d][^\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d]*/, longer_alt: RouteIdentifier } );
  51. // from http://gun.teipir.gr/VRML-amgem/spec/part1/nodesRef.html
  52. var nodeTypes = [
  53. 'Anchor', 'Billboard', 'Collision', 'Group', 'Transform', // grouping nodes
  54. 'Inline', 'LOD', 'Switch', // special groups
  55. 'AudioClip', 'DirectionalLight', 'PointLight', 'Script', 'Shape', 'Sound', 'SpotLight', 'WorldInfo', // common nodes
  56. 'CylinderSensor', 'PlaneSensor', 'ProximitySensor', 'SphereSensor', 'TimeSensor', 'TouchSensor', 'VisibilitySensor', // sensors
  57. 'Box', 'Cone', 'Cylinder', 'ElevationGrid', 'Extrusion', 'IndexedFaceSet', 'IndexedLineSet', 'PointSet', 'Sphere', // geometries
  58. 'Color', 'Coordinate', 'Normal', 'TextureCoordinate', // geometric properties
  59. 'Appearance', 'FontStyle', 'ImageTexture', 'Material', 'MovieTexture', 'PixelTexture', 'TextureTransform', // appearance
  60. 'ColorInterpolator', 'CoordinateInterpolator', 'NormalInterpolator', 'OrientationInterpolator', 'PositionInterpolator', 'ScalarInterpolator', // interpolators
  61. 'Background', 'Fog', 'NavigationInfo', 'Viewpoint', // bindable nodes
  62. 'Text' // Text must be placed at the end of the regex so there are no matches for TextureTransform and TextureCoordinate
  63. ];
  64. //
  65. var Version = createToken( {
  66. name: 'Version',
  67. pattern: /#VRML.*/,
  68. longer_alt: Identifier
  69. } );
  70. var NodeName = createToken( {
  71. name: 'NodeName',
  72. pattern: new RegExp( nodeTypes.join( '|' ) ),
  73. longer_alt: Identifier
  74. } );
  75. var DEF = createToken( {
  76. name: 'DEF',
  77. pattern: /DEF/,
  78. longer_alt: Identifier
  79. } );
  80. var USE = createToken( {
  81. name: 'USE',
  82. pattern: /USE/,
  83. longer_alt: Identifier
  84. } );
  85. var ROUTE = createToken( {
  86. name: 'ROUTE',
  87. pattern: /ROUTE/,
  88. longer_alt: Identifier
  89. } );
  90. var TO = createToken( {
  91. name: 'TO',
  92. pattern: /TO/,
  93. longer_alt: Identifier
  94. } );
  95. //
  96. var StringLiteral = createToken( { name: "StringLiteral", pattern: /"(:?[^\\"\n\r]+|\\(:?[bfnrtv"\\/]|u[0-9a-fA-F]{4}))*"/ } );
  97. var NumberLiteral = createToken( { name: 'NumberLiteral', pattern: /[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?/ } );
  98. var TrueLiteral = createToken( { name: 'TrueLiteral', pattern: /TRUE/ } );
  99. var FalseLiteral = createToken( { name: 'FalseLiteral', pattern: /FALSE/ } );
  100. var NullLiteral = createToken( { name: 'NullLiteral', pattern: /NULL/ } );
  101. var LSquare = createToken( { name: 'LSquare', pattern: /\[/ } );
  102. var RSquare = createToken( { name: 'RSquare', pattern: /]/ } );
  103. var LCurly = createToken( { name: 'LCurly', pattern: /{/ } );
  104. var RCurly = createToken( { name: 'RCurly', pattern: /}/ } );
  105. var Comment = createToken( {
  106. name: 'Comment',
  107. pattern: /#.*/,
  108. group: chevrotain.Lexer.SKIPPED
  109. } );
  110. // commas, blanks, tabs, newlines and carriage returns are whitespace characters wherever they appear outside of string fields
  111. var WhiteSpace = createToken( {
  112. name: 'WhiteSpace',
  113. pattern: /[ ,\s]/,
  114. group: chevrotain.Lexer.SKIPPED
  115. } );
  116. var tokens = [
  117. WhiteSpace,
  118. // keywords appear before the Identifier
  119. NodeName,
  120. DEF,
  121. USE,
  122. ROUTE,
  123. TO,
  124. TrueLiteral,
  125. FalseLiteral,
  126. NullLiteral,
  127. // the Identifier must appear after the keywords because all keywords are valid identifiers
  128. Version,
  129. Identifier,
  130. RouteIdentifier,
  131. StringLiteral,
  132. NumberLiteral,
  133. LSquare,
  134. RSquare,
  135. LCurly,
  136. RCurly,
  137. Comment
  138. ];
  139. var tokenVocabulary = {};
  140. for ( var i = 0, l = tokens.length; i < l; i ++ ) {
  141. var token = tokens[ i ];
  142. tokenVocabulary[ token.name ] = token;
  143. }
  144. return { tokens: tokens, tokenVocabulary: tokenVocabulary };
  145. }
  146. function createVisitor( BaseVRMLVisitor ) {
  147. // the visitor is created dynmaically based on the given base class
  148. function VRMLToASTVisitor() {
  149. BaseVRMLVisitor.call( this );
  150. this.validateVisitor();
  151. }
  152. VRMLToASTVisitor.prototype = Object.assign( Object.create( BaseVRMLVisitor.prototype ), {
  153. constructor: VRMLToASTVisitor,
  154. vrml: function ( ctx ) {
  155. var data = {
  156. version: this.visit( ctx.version ),
  157. nodes: [],
  158. routes: []
  159. };
  160. for ( var i = 0, l = ctx.node.length; i < l; i ++ ) {
  161. var node = ctx.node[ i ];
  162. data.nodes.push( this.visit( node ) );
  163. }
  164. if ( ctx.route ) {
  165. for ( var i = 0, l = ctx.route.length; i < l; i ++ ) {
  166. var route = ctx.route[ i ];
  167. data.routes.push( this.visit( route ) );
  168. }
  169. }
  170. return data;
  171. },
  172. version: function ( ctx ) {
  173. return ctx.Version[ 0 ].image;
  174. },
  175. node: function ( ctx ) {
  176. var data = {
  177. name: ctx.NodeName[ 0 ].image,
  178. fields: []
  179. };
  180. if ( ctx.field ) {
  181. for ( var i = 0, l = ctx.field.length; i < l; i ++ ) {
  182. var field = ctx.field[ i ];
  183. data.fields.push( this.visit( field ) );
  184. }
  185. }
  186. // DEF
  187. if ( ctx.def ) {
  188. data.DEF = this.visit( ctx.def[ 0 ] );
  189. }
  190. return data;
  191. },
  192. field: function ( ctx ) {
  193. var data = {
  194. name: ctx.Identifier[ 0 ].image,
  195. type: null,
  196. values: null
  197. };
  198. var result;
  199. // SFValue
  200. if ( ctx.singleFieldValue ) {
  201. result = this.visit( ctx.singleFieldValue[ 0 ] );
  202. }
  203. // MFValue
  204. if ( ctx.multiFieldValue ) {
  205. result = this.visit( ctx.multiFieldValue[ 0 ] );
  206. }
  207. data.type = result.type;
  208. data.values = result.values;
  209. return data;
  210. },
  211. def: function ( ctx ) {
  212. return ctx.Identifier[ 0 ].image;
  213. },
  214. use: function ( ctx ) {
  215. return { USE: ctx.Identifier[ 0 ].image };
  216. },
  217. singleFieldValue: function ( ctx ) {
  218. return processField( this, ctx );
  219. },
  220. multiFieldValue: function ( ctx ) {
  221. return processField( this, ctx );
  222. },
  223. route: function ( ctx ) {
  224. var data = {
  225. FROM: ctx.RouteIdentifier[ 0 ].image,
  226. TO: ctx.RouteIdentifier[ 1 ].image
  227. };
  228. return data;
  229. }
  230. } );
  231. function processField( scope, ctx ) {
  232. var field = {
  233. type: null,
  234. values: []
  235. };
  236. if ( ctx.node ) {
  237. field.type = 'node';
  238. for ( var i = 0, l = ctx.node.length; i < l; i ++ ) {
  239. var node = ctx.node[ i ];
  240. field.values.push( scope.visit( node ) );
  241. }
  242. }
  243. if ( ctx.use ) {
  244. field.type = 'use';
  245. for ( var i = 0, l = ctx.use.length; i < l; i ++ ) {
  246. var use = ctx.use[ i ];
  247. field.values.push( scope.visit( use ) );
  248. }
  249. }
  250. if ( ctx.StringLiteral ) {
  251. field.type = 'string';
  252. for ( var i = 0, l = ctx.StringLiteral.length; i < l; i ++ ) {
  253. var stringLiteral = ctx.StringLiteral[ i ];
  254. field.values.push( stringLiteral.image.replace( /'|"/g, '' ) );
  255. }
  256. }
  257. if ( ctx.NumberLiteral ) {
  258. field.type = 'number';
  259. for ( var i = 0, l = ctx.NumberLiteral.length; i < l; i ++ ) {
  260. var numberLiteral = ctx.NumberLiteral[ i ];
  261. field.values.push( parseFloat( numberLiteral.image ) );
  262. }
  263. }
  264. if ( ctx.TrueLiteral ) {
  265. field.type = 'boolean';
  266. for ( var i = 0, l = ctx.TrueLiteral.length; i < l; i ++ ) {
  267. var trueLiteral = ctx.TrueLiteral[ i ];
  268. if ( trueLiteral.image === 'TRUE' ) field.values.push( true );
  269. }
  270. }
  271. if ( ctx.FalseLiteral ) {
  272. field.type = 'boolean';
  273. for ( var i = 0, l = ctx.FalseLiteral.length; i < l; i ++ ) {
  274. var falseLiteral = ctx.FalseLiteral[ i ];
  275. if ( falseLiteral.image === 'FALSE' ) field.values.push( false );
  276. }
  277. }
  278. if ( ctx.NullLiteral ) {
  279. field.type = 'null';
  280. ctx.NullLiteral.forEach( function () {
  281. field.values.push( null );
  282. } );
  283. }
  284. return field;
  285. }
  286. return new VRMLToASTVisitor();
  287. }
  288. function parseTree( tree ) {
  289. // console.log( JSON.stringify( tree, null, 2 ) );
  290. var nodes = tree.nodes;
  291. var scene = new THREE.Scene();
  292. // first iteration: build nodemap based on DEF statements
  293. for ( var i = 0, l = nodes.length; i < l; i ++ ) {
  294. var node = nodes[ i ];
  295. buildNodeMap( node );
  296. }
  297. // second iteration: build nodes
  298. for ( var i = 0, l = nodes.length; i < l; i ++ ) {
  299. var node = nodes[ i ];
  300. var object = getNode( node );
  301. if ( object instanceof THREE.Object3D ) scene.add( object );
  302. }
  303. return scene;
  304. }
  305. function buildNodeMap( node ) {
  306. if ( node.DEF ) {
  307. nodeMap[ node.DEF ] = node;
  308. }
  309. var fields = node.fields;
  310. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  311. var field = fields[ i ];
  312. if ( field.type === 'node' ) {
  313. var fieldValues = field.values;
  314. for ( var j = 0, jl = fieldValues.length; j < jl; j ++ ) {
  315. buildNodeMap( fieldValues[ j ] );
  316. }
  317. }
  318. }
  319. }
  320. function getNode( node ) {
  321. // handle case where a node refers to a different one
  322. if ( node.USE ) {
  323. return resolveUSE( node.USE );
  324. }
  325. if ( node.build !== undefined ) return node.build;
  326. node.build = buildNode( node );
  327. return node.build;
  328. }
  329. // node builder
  330. function buildNode( node ) {
  331. var nodeName = node.name;
  332. var build;
  333. switch ( nodeName ) {
  334. case 'Group':
  335. case 'Transform':
  336. build = buildGroupingNode( node );
  337. break;
  338. case 'Background':
  339. build = buildBackgroundNode( node );
  340. break;
  341. case 'Shape':
  342. build = buildShapeNode( node );
  343. break;
  344. case 'Appearance':
  345. build = buildApperanceNode( node );
  346. break;
  347. case 'Material':
  348. build = buildMaterialNode( node );
  349. break;
  350. case 'ImageTexture':
  351. build = buildImageTextureNode( node );
  352. break;
  353. case 'TextureTransform':
  354. build = buildTextureTransformNode( node );
  355. break;
  356. case 'IndexedFaceSet':
  357. build = buildIndexedFaceSetNode( node );
  358. break;
  359. case 'IndexedLineSet':
  360. build = buildIndexedLineSetNode( node );
  361. break;
  362. case 'PointSet':
  363. build = buildPointSetNode( node );
  364. break;
  365. case 'Box':
  366. build = buildBoxNode( node );
  367. break;
  368. case 'Cone':
  369. build = buildConeNode( node );
  370. break;
  371. case 'Cylinder':
  372. build = buildCylinderNode( node );
  373. break;
  374. case 'Sphere':
  375. build = buildSphereNode( node );
  376. break;
  377. case 'Color':
  378. case 'Coordinate':
  379. case 'Normal':
  380. case 'TextureCoordinate':
  381. build = buildGeometricNode( node );
  382. break;
  383. case 'Anchor':
  384. case 'Billboard':
  385. case 'Collision':
  386. case 'Inline':
  387. case 'LOD':
  388. case 'Switch':
  389. case 'AudioClip':
  390. case 'DirectionalLight':
  391. case 'PointLight':
  392. case 'Script':
  393. case 'Sound':
  394. case 'SpotLight':
  395. case 'WorldInfo':
  396. case 'CylinderSensor':
  397. case 'PlaneSensor':
  398. case 'ProximitySensor':
  399. case 'SphereSensor':
  400. case 'TimeSensor':
  401. case 'TouchSensor':
  402. case 'VisibilitySensor':
  403. case 'ElevationGrid':
  404. case 'Extrusion':
  405. case 'Text':
  406. case 'FontStyle':
  407. case 'MovieTexture':
  408. case 'PixelTexture':
  409. case 'ColorInterpolator':
  410. case 'CoordinateInterpolator':
  411. case 'NormalInterpolator':
  412. case 'OrientationInterpolator':
  413. case 'PositionInterpolator':
  414. case 'ScalarInterpolator':
  415. case 'Fog':
  416. case 'NavigationInfo':
  417. case 'Viewpoint':
  418. // node not supported yet
  419. break;
  420. default:
  421. console.warn( 'THREE.VRMLLoader: Unknown node:', nodeName );
  422. break;
  423. }
  424. return build;
  425. }
  426. function buildGroupingNode( node ) {
  427. var object = new THREE.Group();
  428. //
  429. var fields = node.fields;
  430. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  431. var field = fields[ i ];
  432. var fieldName = field.name;
  433. var fieldValues = field.values;
  434. switch ( fieldName ) {
  435. case 'center':
  436. // field not supported
  437. break;
  438. case 'children':
  439. parseFieldChildren( fieldValues, object );
  440. break;
  441. case 'rotation':
  442. var axis = new THREE.Vector3( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
  443. var angle = fieldValues[ 3 ];
  444. object.quaternion.setFromAxisAngle( axis, angle );
  445. break;
  446. case 'scale':
  447. object.scale.set( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
  448. break;
  449. case 'scaleOrientation':
  450. // field not supported
  451. break;
  452. case 'translation':
  453. object.position.set( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
  454. break;
  455. case 'bboxCenter':
  456. // field not supported
  457. break;
  458. case 'bboxSize':
  459. // field not supported
  460. break;
  461. default:
  462. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  463. break;
  464. }
  465. }
  466. return object;
  467. }
  468. function buildBackgroundNode( node ) {
  469. var group = new THREE.Group();
  470. var groundAngle, groundColor;
  471. var skyAngle, skyColor;
  472. var fields = node.fields;
  473. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  474. var field = fields[ i ];
  475. var fieldName = field.name;
  476. var fieldValues = field.values;
  477. switch ( fieldName ) {
  478. case 'groundAngle':
  479. groundAngle = fieldValues;
  480. break;
  481. case 'groundColor':
  482. groundColor = fieldValues;
  483. break;
  484. case 'backUrl':
  485. // field not supported
  486. break;
  487. case 'bottomUrl':
  488. // field not supported
  489. break;
  490. case 'frontUrl':
  491. // field not supported
  492. break;
  493. case 'leftUrl':
  494. // field not supported
  495. break;
  496. case 'rightUrl':
  497. // field not supported
  498. break;
  499. case 'topUrl':
  500. // field not supported
  501. break;
  502. case 'skyAngle':
  503. skyAngle = fieldValues;
  504. break;
  505. case 'skyColor':
  506. skyColor = fieldValues;
  507. break;
  508. default:
  509. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  510. break;
  511. }
  512. }
  513. // sky
  514. if ( skyColor ) {
  515. var radius = 10000;
  516. var skyGeometry = new THREE.SphereBufferGeometry( radius, 32, 16 );
  517. var skyMaterial = new THREE.MeshBasicMaterial( { fog: false, side: THREE.BackSide, depthWrite: false, depthTest: false } );
  518. if ( skyColor.length > 3 ) {
  519. paintFaces( skyGeometry, radius, skyAngle, toColorArray( skyColor ), true );
  520. skyMaterial.vertexColors = THREE.VertexColors;
  521. } else {
  522. skyMaterial.color.setRGB( skyColor[ 0 ], skyColor[ 1 ], skyColor[ 2 ] );
  523. }
  524. var sky = new THREE.Mesh( skyGeometry, skyMaterial );
  525. group.add( sky );
  526. }
  527. // ground
  528. if ( groundColor ) {
  529. if ( groundColor.length > 0 ) {
  530. var groundGeometry = new THREE.SphereBufferGeometry( radius, 32, 16, 0, 2 * Math.PI, 0.5 * Math.PI, 1.5 * Math.PI );
  531. var groundMaterial = new THREE.MeshBasicMaterial( { fog: false, side: THREE.BackSide, vertexColors: THREE.VertexColors, depthWrite: false, depthTest: false } );
  532. paintFaces( groundGeometry, radius, groundAngle, toColorArray( groundColor ), false );
  533. var ground = new THREE.Mesh( groundGeometry, groundMaterial );
  534. group.add( ground );
  535. }
  536. }
  537. // render background group first
  538. group.renderOrder = - Infinity;
  539. return group;
  540. }
  541. function buildShapeNode( node ) {
  542. var fields = node.fields;
  543. // if the appearance field is NULL or unspecified, lighting is off and the unlit object color is (0, 0, 0)
  544. var material = new THREE.MeshBasicMaterial( { color: 0x000000 } );
  545. var geometry;
  546. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  547. var field = fields[ i ];
  548. var fieldName = field.name;
  549. var fieldValues = field.values;
  550. switch ( fieldName ) {
  551. case 'appearance':
  552. if ( fieldValues[ 0 ] !== null ) {
  553. material = getNode( fieldValues[ 0 ] );
  554. }
  555. break;
  556. case 'geometry':
  557. if ( fieldValues[ 0 ] !== null ) {
  558. geometry = getNode( fieldValues[ 0 ] );
  559. }
  560. break;
  561. default:
  562. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  563. break;
  564. }
  565. }
  566. // build 3D object
  567. var object;
  568. if ( geometry && geometry.attributes.position ) {
  569. var type = geometry._type;
  570. if ( type === 'points' ) { // points
  571. var pointsMaterial = new THREE.PointsMaterial( { color: 0xffffff } );
  572. if ( geometry.attributes.color !== undefined ) {
  573. pointsMaterial.vertexColors = THREE.VertexColors;
  574. } else {
  575. // 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
  576. if ( material.isMeshPhongMaterial ) {
  577. pointsMaterial.color.copy( material.emissive );
  578. }
  579. }
  580. object = new THREE.Points( geometry, pointsMaterial );
  581. } else if ( type === 'line' ) { // lines
  582. var lineMaterial = new THREE.LineBasicMaterial( { color: 0xffffff } );
  583. if ( geometry.attributes.color !== undefined ) {
  584. lineMaterial.vertexColors = THREE.VertexColors;
  585. } else {
  586. // 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
  587. if ( material.isMeshPhongMaterial ) {
  588. lineMaterial.color.copy( material.emissive );
  589. }
  590. }
  591. object = new THREE.LineSegments( geometry, lineMaterial );
  592. } else { // consider meshes
  593. // check "solid" hint (it's placed in the geometry but affects the material)
  594. if ( geometry._solid !== undefined ) {
  595. material.side = ( geometry._solid ) ? THREE.FrontSide : THREE.DoubleSide;
  596. }
  597. // check for vertex colors
  598. if ( geometry.attributes.color !== undefined ) {
  599. material.vertexColors = THREE.VertexColors;
  600. }
  601. object = new THREE.Mesh( geometry, material );
  602. }
  603. } else {
  604. object = new THREE.Object3D();
  605. // if the geometry field is NULL or no vertices are defined the object is not drawn
  606. object.visible = false;
  607. }
  608. return object;
  609. }
  610. function buildApperanceNode( node ) {
  611. var material = new THREE.MeshPhongMaterial();
  612. var transformData;
  613. var fields = node.fields;
  614. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  615. var field = fields[ i ];
  616. var fieldName = field.name;
  617. var fieldValues = field.values;
  618. switch ( fieldName ) {
  619. case 'material':
  620. if ( fieldValues[ 0 ] !== null ) {
  621. var materialData = getNode( fieldValues[ 0 ] );
  622. if ( materialData.diffuseColor ) material.color.copy( materialData.diffuseColor );
  623. if ( materialData.emissiveColor ) material.emissive.copy( materialData.emissiveColor );
  624. if ( materialData.shininess ) material.shininess = materialData.shininess;
  625. if ( materialData.specularColor ) material.specular.copy( materialData.specularColor );
  626. if ( materialData.transparency ) material.opacity = 1 - materialData.transparency;
  627. if ( materialData.transparency > 0 ) material.transparent = true;
  628. } else {
  629. // if the material field is NULL or unspecified, lighting is off and the unlit object color is (0, 0, 0)
  630. material = new THREE.MeshBasicMaterial( { color: 0x000000 } );
  631. }
  632. break;
  633. case 'texture':
  634. var textureNode = fieldValues[ 0 ];
  635. if ( textureNode !== null ) {
  636. if ( textureNode.name === 'ImageTexture' ) {
  637. material.map = getNode( textureNode );
  638. } else {
  639. // MovieTexture and PixelTexture not supported yet
  640. }
  641. }
  642. break;
  643. case 'textureTransform':
  644. if ( fieldValues[ 0 ] !== null ) {
  645. transformData = getNode( fieldValues[ 0 ] );
  646. }
  647. break;
  648. default:
  649. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  650. break;
  651. }
  652. }
  653. // only apply texture transform data if a texture was defined
  654. if ( material.map && transformData ) {
  655. material.map.center.copy( transformData.center );
  656. material.map.rotation = transformData.rotation;
  657. material.map.repeat.copy( transformData.scale );
  658. material.map.offset.copy( transformData.translation );
  659. }
  660. return material;
  661. }
  662. function buildMaterialNode( node ) {
  663. var materialData = {};
  664. var fields = node.fields;
  665. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  666. var field = fields[ i ];
  667. var fieldName = field.name;
  668. var fieldValues = field.values;
  669. switch ( fieldName ) {
  670. case 'ambientIntensity':
  671. // field not supported
  672. break;
  673. case 'diffuseColor':
  674. materialData.diffuseColor = new THREE.Color( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
  675. break;
  676. case 'emissiveColor':
  677. materialData.emissiveColor = new THREE.Color( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
  678. break;
  679. case 'shininess':
  680. materialData.shininess = fieldValues[ 0 ];
  681. break;
  682. case 'specularColor':
  683. materialData.emissiveColor = new THREE.Color( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
  684. break;
  685. case 'transparency':
  686. materialData.transparency = fieldValues[ 0 ];
  687. break;
  688. default:
  689. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  690. break;
  691. }
  692. }
  693. return materialData;
  694. }
  695. function buildImageTextureNode( node ) {
  696. var texture;
  697. var wrapS = THREE.RepeatWrapping;
  698. var wrapT = THREE.RepeatWrapping;
  699. var fields = node.fields;
  700. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  701. var field = fields[ i ];
  702. var fieldName = field.name;
  703. var fieldValues = field.values;
  704. switch ( fieldName ) {
  705. case 'url':
  706. var url = fieldValues[ 0 ];
  707. if ( url ) texture = textureLoader.load( url );
  708. break;
  709. case 'repeatS':
  710. if ( fieldValues[ 0 ] === false ) wrapS = THREE.ClampToEdgeWrapping;
  711. break;
  712. case 'repeatT':
  713. if ( fieldValues[ 0 ] === false ) wrapT = THREE.ClampToEdgeWrapping;
  714. break;
  715. default:
  716. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  717. break;
  718. }
  719. }
  720. if ( texture ) {
  721. texture.wrapS = wrapS;
  722. texture.wrapT = wrapT;
  723. }
  724. return texture;
  725. }
  726. function buildTextureTransformNode( node ) {
  727. var transformData = {
  728. center: new THREE.Vector2(),
  729. rotation: new THREE.Vector2(),
  730. scale: new THREE.Vector2(),
  731. translation: new THREE.Vector2()
  732. };
  733. var fields = node.fields;
  734. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  735. var field = fields[ i ];
  736. var fieldName = field.name;
  737. var fieldValues = field.values;
  738. switch ( fieldName ) {
  739. case 'center':
  740. transformData.center.set( fieldValues[ 0 ], fieldValues[ 1 ] );
  741. break;
  742. case 'rotation':
  743. transformData.rotation = fieldValues[ 0 ];
  744. break;
  745. case 'scale':
  746. transformData.scale.set( fieldValues[ 0 ], fieldValues[ 1 ] );
  747. break;
  748. case 'translation':
  749. transformData.translation.set( fieldValues[ 0 ], fieldValues[ 1 ] );
  750. break;
  751. default:
  752. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  753. break;
  754. }
  755. }
  756. return transformData;
  757. }
  758. function buildGeometricNode( node ) {
  759. return node.fields[ 0 ].values;
  760. }
  761. function buildIndexedFaceSetNode( node ) {
  762. var color, coord, normal, texCoord;
  763. var ccw = true, solid = true, creaseAngle = 0;
  764. var colorIndex, coordIndex, normalIndex, texCoordIndex;
  765. var colorPerVertex = true, normalPerVertex = true;
  766. var fields = node.fields;
  767. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  768. var field = fields[ i ];
  769. var fieldName = field.name;
  770. var fieldValues = field.values;
  771. switch ( fieldName ) {
  772. case 'color':
  773. var colorNode = fieldValues[ 0 ];
  774. if ( colorNode !== null ) {
  775. color = getNode( colorNode );
  776. }
  777. break;
  778. case 'coord':
  779. var coordNode = fieldValues[ 0 ];
  780. if ( coordNode !== null ) {
  781. coord = getNode( coordNode );
  782. }
  783. break;
  784. case 'normal':
  785. var normalNode = fieldValues[ 0 ];
  786. if ( normalNode !== null ) {
  787. normal = getNode( normalNode );
  788. }
  789. break;
  790. case 'texCoord':
  791. var texCoordNode = fieldValues[ 0 ];
  792. if ( texCoordNode !== null ) {
  793. texCoord = getNode( texCoordNode );
  794. }
  795. break;
  796. case 'ccw':
  797. ccw = fieldValues[ 0 ];
  798. break;
  799. case 'colorIndex':
  800. colorIndex = fieldValues;
  801. break;
  802. case 'colorPerVertex':
  803. colorPerVertex = fieldValues[ 0 ];
  804. break;
  805. case 'convex':
  806. // field not supported
  807. break;
  808. case 'coordIndex':
  809. coordIndex = fieldValues;
  810. break;
  811. case 'creaseAngle':
  812. creaseAngle = fieldValues[ 0 ];
  813. break;
  814. case 'normalIndex':
  815. normalIndex = fieldValues;
  816. break;
  817. case 'normalPerVertex':
  818. normalPerVertex = fieldValues[ 0 ];
  819. break;
  820. case 'solid':
  821. solid = fieldValues[ 0 ];
  822. break;
  823. case 'texCoordIndex':
  824. texCoordIndex = fieldValues;
  825. break;
  826. default:
  827. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  828. break;
  829. }
  830. }
  831. if ( coordIndex === undefined ) {
  832. console.warn( 'THREE.VRMLLoader: Missing coordIndex.' );
  833. return new THREE.BufferGeometry(); // handle VRML files with incomplete geometry definition
  834. }
  835. var triangulatedCoordIndex = triangulateFaceIndex( coordIndex, ccw );
  836. var positionAttribute;
  837. var colorAttribute;
  838. var normalAttribute;
  839. var uvAttribute;
  840. if ( color ) {
  841. if ( colorPerVertex === true ) {
  842. if ( colorIndex && colorIndex.length > 0 ) {
  843. // if the colorIndex field is not empty, then it is used to choose colors for each vertex of the IndexedFaceSet.
  844. var triangulatedColorIndex = triangulateFaceIndex( colorIndex, ccw );
  845. colorAttribute = computeAttributeFromIndexedData( triangulatedCoordIndex, triangulatedColorIndex, color, 3 );
  846. } else {
  847. // if the colorIndex field is empty, then the coordIndex field is used to choose colors from the Color node
  848. colorAttribute = toNonIndexedAttribute( triangulatedCoordIndex, new THREE.Float32BufferAttribute( color, 3 ) );
  849. }
  850. } else {
  851. if ( colorIndex && colorIndex.length > 0 ) {
  852. // if the colorIndex field is not empty, then they are used to choose one color for each face of the IndexedFaceSet
  853. var flattenFaceColors = flattenData( color, colorIndex );
  854. var triangulatedFaceColors = triangulateFaceData( flattenFaceColors, coordIndex );
  855. colorAttribute = computeAttributeFromFaceData( triangulatedCoordIndex, triangulatedFaceColors );
  856. } else {
  857. // if the colorIndex field is empty, then the color are applied to each face of the IndexedFaceSet in order
  858. var triangulatedFaceColors = triangulateFaceData( color, coordIndex );
  859. colorAttribute = computeAttributeFromFaceData( triangulatedCoordIndex, triangulatedFaceColors );
  860. }
  861. }
  862. }
  863. if ( normal ) {
  864. if ( normalPerVertex === true ) {
  865. // consider vertex normals
  866. if ( normalIndex && normalIndex.length > 0 ) {
  867. // if the normalIndex field is not empty, then it is used to choose normals for each vertex of the IndexedFaceSet.
  868. var triangulatedNormalIndex = triangulateFaceIndex( normalIndex, ccw );
  869. normalAttribute = computeAttributeFromIndexedData( triangulatedCoordIndex, triangulatedNormalIndex, normal, 3 );
  870. } else {
  871. // if the normalIndex field is empty, then the coordIndex field is used to choose normals from the Normal node
  872. normalAttribute = toNonIndexedAttribute( triangulatedCoordIndex, new THREE.Float32BufferAttribute( normal, 3 ) );
  873. }
  874. } else {
  875. // consider face normals
  876. if ( normalIndex && normalIndex.length > 0 ) {
  877. // if the normalIndex field is not empty, then they are used to choose one normal for each face of the IndexedFaceSet
  878. var flattenFaceNormals = flattenData( normal, normalIndex );
  879. var triangulatedFaceNormals = triangulateFaceData( flattenFaceNormals, coordIndex );
  880. normalAttribute = computeAttributeFromFaceData( triangulatedCoordIndex, triangulatedFaceNormals );
  881. } else {
  882. // if the normalIndex field is empty, then the normals are applied to each face of the IndexedFaceSet in order
  883. var triangulatedFaceNormals = triangulateFaceData( normal, coordIndex );
  884. normalAttribute = computeAttributeFromFaceData( triangulatedCoordIndex, triangulatedFaceNormals );
  885. }
  886. }
  887. } else {
  888. // 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
  889. normalAttribute = computeNormalAttribute( triangulatedCoordIndex, coord, creaseAngle );
  890. }
  891. if ( texCoord ) {
  892. // texture coordinates are always defined on vertex level
  893. if ( texCoordIndex && texCoordIndex.length > 0 ) {
  894. // if the texCoordIndex field is not empty, then it is used to choose texture coordinates for each vertex of the IndexedFaceSet.
  895. var triangulatedTexCoordIndex = triangulateFaceIndex( texCoordIndex, ccw );
  896. uvAttribute = computeAttributeFromIndexedData( triangulatedCoordIndex, triangulatedTexCoordIndex, texCoord, 2 );
  897. } else {
  898. // if the texCoordIndex field is empty, then the coordIndex array is used to choose texture coordinates from the TextureCoordinate node
  899. uvAttribute = toNonIndexedAttribute( triangulatedCoordIndex, new THREE.Float32BufferAttribute( texCoord, 2 ) );
  900. }
  901. }
  902. var geometry = new THREE.BufferGeometry();
  903. positionAttribute = toNonIndexedAttribute( triangulatedCoordIndex, new THREE.Float32BufferAttribute( coord, 3 ) );
  904. geometry.addAttribute( 'position', positionAttribute );
  905. geometry.addAttribute( 'normal', normalAttribute );
  906. // optional attributes
  907. if ( colorAttribute ) geometry.addAttribute( 'color', colorAttribute );
  908. if ( uvAttribute ) geometry.addAttribute( 'uv', uvAttribute );
  909. // "solid" influences the material so let's store it for later use
  910. geometry._solid = solid;
  911. geometry._type = 'mesh';
  912. return geometry;
  913. }
  914. function buildIndexedLineSetNode( node ) {
  915. var color, coord;
  916. var colorIndex, coordIndex;
  917. var colorPerVertex = true;
  918. var fields = node.fields;
  919. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  920. var field = fields[ i ];
  921. var fieldName = field.name;
  922. var fieldValues = field.values;
  923. switch ( fieldName ) {
  924. case 'color':
  925. var colorNode = fieldValues[ 0 ];
  926. if ( colorNode !== null ) {
  927. color = getNode( colorNode );
  928. }
  929. break;
  930. case 'coord':
  931. var coordNode = fieldValues[ 0 ];
  932. if ( coordNode !== null ) {
  933. coord = getNode( coordNode );
  934. }
  935. break;
  936. case 'colorIndex':
  937. colorIndex = fieldValues;
  938. break;
  939. case 'colorPerVertex':
  940. colorPerVertex = fieldValues[ 0 ];
  941. break;
  942. case 'coordIndex':
  943. coordIndex = fieldValues;
  944. break;
  945. default:
  946. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  947. break;
  948. }
  949. }
  950. // build lines
  951. var colorAttribute;
  952. var expandedLineIndex = expandLineIndex( coordIndex ); // create an index for three.js's linesegment primitive
  953. if ( color ) {
  954. if ( colorPerVertex === true ) {
  955. if ( colorIndex.length > 0 ) {
  956. // if the colorIndex field is not empty, then one color is used for each polyline of the IndexedLineSet.
  957. var expandedColorIndex = expandLineIndex( colorIndex ); // compute colors for each line segment (rendering primitve)
  958. colorAttribute = computeAttributeFromIndexedData( expandedLineIndex, expandedColorIndex, color, 3 ); // compute data on vertex level
  959. } else {
  960. // if the colorIndex field is empty, then the colors are applied to each polyline of the IndexedLineSet in order.
  961. colorAttribute = toNonIndexedAttribute( expandedLineIndex, new THREE.Float32BufferAttribute( color, 3 ) );
  962. }
  963. } else {
  964. if ( colorIndex.length > 0 ) {
  965. // if the colorIndex field is not empty, then colors are applied to each vertex of the IndexedLineSet
  966. var flattenLineColors = flattenData( color, colorIndex ); // compute colors for each VRML primitve
  967. var expandedLineColors = expandLineData( flattenLineColors, coordIndex ); // compute colors for each line segment (rendering primitve)
  968. colorAttribute = computeAttributeFromLineData( expandedLineIndex, expandedLineColors ); // compute data on vertex level
  969. } else {
  970. // if the colorIndex field is empty, then the coordIndex field is used to choose colors from the Color node
  971. var expandedLineColors = expandLineData( color, coordIndex ); // compute colors for each line segment (rendering primitve)
  972. colorAttribute = computeAttributeFromLineData( expandedLineIndex, expandedLineColors ); // compute data on vertex level
  973. }
  974. }
  975. }
  976. //
  977. var geometry = new THREE.BufferGeometry();
  978. var positionAttribute = toNonIndexedAttribute( expandedLineIndex, new THREE.Float32BufferAttribute( coord, 3 ) );
  979. geometry.addAttribute( 'position', positionAttribute );
  980. if ( colorAttribute ) geometry.addAttribute( 'color', colorAttribute );
  981. geometry._type = 'line';
  982. return geometry;
  983. }
  984. function buildPointSetNode( node ) {
  985. var geometry;
  986. var color, coord;
  987. var fields = node.fields;
  988. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  989. var field = fields[ i ];
  990. var fieldName = field.name;
  991. var fieldValues = field.values;
  992. switch ( fieldName ) {
  993. case 'color':
  994. var colorNode = fieldValues[ 0 ];
  995. if ( colorNode !== null ) {
  996. color = getNode( colorNode );
  997. }
  998. break;
  999. case 'coord':
  1000. var coordNode = fieldValues[ 0 ];
  1001. if ( coordNode !== null ) {
  1002. coord = getNode( coordNode );
  1003. }
  1004. break;
  1005. default:
  1006. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  1007. break;
  1008. }
  1009. }
  1010. var geometry = new THREE.BufferGeometry();
  1011. geometry.addAttribute( 'position', new THREE.Float32BufferAttribute( coord, 3 ) );
  1012. if ( color ) geometry.addAttribute( 'color', new THREE.Float32BufferAttribute( color, 3 ) );
  1013. geometry._type = 'points';
  1014. return geometry;
  1015. }
  1016. function buildBoxNode( node ) {
  1017. var size = new THREE.Vector3( 2, 2, 2 );
  1018. var fields = node.fields;
  1019. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  1020. var field = fields[ i ];
  1021. var fieldName = field.name;
  1022. var fieldValues = field.values;
  1023. switch ( fieldName ) {
  1024. case 'size':
  1025. size.x = fieldValues[ 0 ];
  1026. size.y = fieldValues[ 1 ];
  1027. size.z = fieldValues[ 2 ];
  1028. break;
  1029. default:
  1030. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  1031. break;
  1032. }
  1033. }
  1034. var geometry = new THREE.BoxBufferGeometry( size.x, size.y, size.z );
  1035. return geometry;
  1036. }
  1037. function buildConeNode( node ) {
  1038. var radius = 1, height = 2, openEnded = false;
  1039. var fields = node.fields;
  1040. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  1041. var field = fields[ i ];
  1042. var fieldName = field.name;
  1043. var fieldValues = field.values;
  1044. switch ( fieldName ) {
  1045. case 'bottom':
  1046. openEnded = ! fieldValues[ 0 ];
  1047. break;
  1048. case 'bottomRadius':
  1049. radius = fieldValues[ 0 ];
  1050. break;
  1051. case 'height':
  1052. height = fieldValues[ 0 ];
  1053. break;
  1054. case 'side':
  1055. // field not supported
  1056. break;
  1057. default:
  1058. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  1059. break;
  1060. }
  1061. }
  1062. var geometry = new THREE.ConeBufferGeometry( radius, height, 16, 1, openEnded );
  1063. return geometry;
  1064. }
  1065. function buildCylinderNode( node ) {
  1066. var radius = 1, height = 2;
  1067. var fields = node.fields;
  1068. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  1069. var field = fields[ i ];
  1070. var fieldName = field.name;
  1071. var fieldValues = field.values;
  1072. switch ( fieldName ) {
  1073. case 'bottom':
  1074. // field not supported
  1075. break;
  1076. case 'radius':
  1077. radius = fieldValues[ 0 ];
  1078. break;
  1079. case 'height':
  1080. height = fieldValues[ 0 ];
  1081. break;
  1082. case 'side':
  1083. // field not supported
  1084. break;
  1085. case 'top':
  1086. // field not supported
  1087. break;
  1088. default:
  1089. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  1090. break;
  1091. }
  1092. }
  1093. var geometry = new THREE.CylinderBufferGeometry( radius, radius, height, 16, 1 );
  1094. return geometry;
  1095. }
  1096. function buildSphereNode( node ) {
  1097. var radius = 1;
  1098. var fields = node.fields;
  1099. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  1100. var field = fields[ i ];
  1101. var fieldName = field.name;
  1102. var fieldValues = field.values;
  1103. switch ( fieldName ) {
  1104. case 'radius':
  1105. radius = fieldValues[ 0 ];
  1106. break;
  1107. default:
  1108. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  1109. break;
  1110. }
  1111. }
  1112. var geometry = new THREE.SphereBufferGeometry( radius, 16, 16 );
  1113. return geometry;
  1114. }
  1115. // helper functions
  1116. function resolveUSE( identifier ) {
  1117. var node = nodeMap[ identifier ];
  1118. var build = getNode( node );
  1119. // because the same 3D objects can have different transformations, it's necessary to clone them.
  1120. // materials can be influenced by the geometry (e.g. vertex normals). cloning is necessary to avoid
  1121. // any side effects
  1122. return ( build.isObject3D || build.isMaterial ) ? build.clone() : build;
  1123. }
  1124. function parseFieldChildren( children, owner ) {
  1125. for ( var i = 0, l = children.length; i < l; i ++ ) {
  1126. var object = getNode( children[ i ] );
  1127. if ( object instanceof THREE.Object3D ) owner.add( object );
  1128. }
  1129. }
  1130. function triangulateFaceIndex( index, ccw ) {
  1131. var indices = [];
  1132. // since face defintions can have more than three vertices, it's necessary to
  1133. // perform a simple triangulation
  1134. var start = 0;
  1135. for ( var i = 0, l = index.length; i < l; i ++ ) {
  1136. var i1 = index[ start ];
  1137. var i2 = index[ i + ( ccw ? 1 : 2 ) ];
  1138. var i3 = index[ i + ( ccw ? 2 : 1 ) ];
  1139. indices.push( i1, i2, i3 );
  1140. // an index of -1 indicates that the current face has ended and the next one begins
  1141. if ( index[ i + 3 ] === - 1 || i + 3 >= l ) {
  1142. i += 3;
  1143. start = i + 1;
  1144. }
  1145. }
  1146. return indices;
  1147. }
  1148. function triangulateFaceData( data, index ) {
  1149. var triangulatedData = [];
  1150. var start = 0;
  1151. for ( var i = 0, l = index.length; i < l; i ++ ) {
  1152. var stride = start * 3;
  1153. var x = data[ stride ];
  1154. var y = data[ stride + 1 ];
  1155. var z = data[ stride + 2 ];
  1156. triangulatedData.push( x, y, z );
  1157. // an index of -1 indicates that the current face has ended and the next one begins
  1158. if ( index[ i + 3 ] === - 1 || i + 3 >= l ) {
  1159. i += 3;
  1160. start ++;
  1161. }
  1162. }
  1163. return triangulatedData;
  1164. }
  1165. function flattenData( data, index ) {
  1166. var flattenData = [];
  1167. for ( var i = 0, l = index.length; i < l; i ++ ) {
  1168. var i1 = index[ i ];
  1169. var stride = i1 * 3;
  1170. var x = data[ stride ];
  1171. var y = data[ stride + 1 ];
  1172. var z = data[ stride + 2 ];
  1173. flattenData.push( x, y, z );
  1174. }
  1175. return flattenData;
  1176. }
  1177. function expandLineIndex( index ) {
  1178. var indices = [];
  1179. for ( var i = 0, l = index.length; i < l; i ++ ) {
  1180. var i1 = index[ i ];
  1181. var i2 = index[ i + 1 ];
  1182. indices.push( i1, i2 );
  1183. // an index of -1 indicates that the current line has ended and the next one begins
  1184. if ( index[ i + 2 ] === - 1 || i + 2 >= l ) {
  1185. i += 2;
  1186. }
  1187. }
  1188. return indices;
  1189. }
  1190. function expandLineData( data, index ) {
  1191. var triangulatedData = [];
  1192. var start = 0;
  1193. for ( var i = 0, l = index.length; i < l; i ++ ) {
  1194. var stride = start * 3;
  1195. var x = data[ stride ];
  1196. var y = data[ stride + 1 ];
  1197. var z = data[ stride + 2 ];
  1198. triangulatedData.push( x, y, z );
  1199. // an index of -1 indicates that the current line has ended and the next one begins
  1200. if ( index[ i + 2 ] === - 1 || i + 2 >= l ) {
  1201. i += 2;
  1202. start ++;
  1203. }
  1204. }
  1205. return triangulatedData;
  1206. }
  1207. var vA = new THREE.Vector3();
  1208. var vB = new THREE.Vector3();
  1209. var vC = new THREE.Vector3();
  1210. var uvA = new THREE.Vector2();
  1211. var uvB = new THREE.Vector2();
  1212. var uvC = new THREE.Vector2();
  1213. function computeAttributeFromIndexedData( coordIndex, index, data, itemSize ) {
  1214. var array = [];
  1215. // we use the coordIndex.length as delimiter since normalIndex must contain at least as many indices
  1216. for ( var i = 0, l = coordIndex.length; i < l; i += 3 ) {
  1217. var a = index[ i ];
  1218. var b = index[ i + 1 ];
  1219. var c = index[ i + 2 ];
  1220. if ( itemSize === 2 ) {
  1221. uvA.fromArray( data, a * itemSize );
  1222. uvB.fromArray( data, b * itemSize );
  1223. uvC.fromArray( data, c * itemSize );
  1224. array.push( uvA.x, uvA.y );
  1225. array.push( uvB.x, uvB.y );
  1226. array.push( uvC.x, uvC.y );
  1227. } else {
  1228. vA.fromArray( data, a * itemSize );
  1229. vB.fromArray( data, b * itemSize );
  1230. vC.fromArray( data, c * itemSize );
  1231. array.push( vA.x, vA.y, vA.z );
  1232. array.push( vB.x, vB.y, vB.z );
  1233. array.push( vC.x, vC.y, vC.z );
  1234. }
  1235. }
  1236. return new THREE.Float32BufferAttribute( array, itemSize );
  1237. }
  1238. function computeAttributeFromFaceData( index, faceData ) {
  1239. var array = [];
  1240. for ( var i = 0, j = 0, l = index.length; i < l; i += 3, j ++ ) {
  1241. vA.fromArray( faceData, j * 3 );
  1242. array.push( vA.x, vA.y, vA.z );
  1243. array.push( vA.x, vA.y, vA.z );
  1244. array.push( vA.x, vA.y, vA.z );
  1245. }
  1246. return new THREE.Float32BufferAttribute( array, 3 );
  1247. }
  1248. function computeAttributeFromLineData( index, lineData ) {
  1249. var array = [];
  1250. for ( var i = 0, j = 0, l = index.length; i < l; i += 2, j ++ ) {
  1251. vA.fromArray( lineData, j * 3 );
  1252. array.push( vA.x, vA.y, vA.z );
  1253. array.push( vA.x, vA.y, vA.z );
  1254. }
  1255. return new THREE.Float32BufferAttribute( array, 3 );
  1256. }
  1257. function toNonIndexedAttribute( indices, attribute ) {
  1258. var array = attribute.array;
  1259. var itemSize = attribute.itemSize;
  1260. var array2 = new array.constructor( indices.length * itemSize );
  1261. var index = 0, index2 = 0;
  1262. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  1263. index = indices[ i ] * itemSize;
  1264. for ( var j = 0; j < itemSize; j ++ ) {
  1265. array2[ index2 ++ ] = array[ index ++ ];
  1266. }
  1267. }
  1268. return new THREE.Float32BufferAttribute( array2, itemSize );
  1269. }
  1270. var ab = new THREE.Vector3();
  1271. var cb = new THREE.Vector3();
  1272. function computeNormalAttribute( index, coord, creaseAngle ) {
  1273. var faces = [];
  1274. var vertexNormals = {};
  1275. // prepare face and raw vertex normals
  1276. for ( var i = 0, l = index.length; i < l; i += 3 ) {
  1277. var a = index[ i ];
  1278. var b = index[ i + 1 ];
  1279. var c = index[ i + 2 ];
  1280. var face = new Face( a, b, c );
  1281. vA.fromArray( coord, a * 3 );
  1282. vB.fromArray( coord, b * 3 );
  1283. vC.fromArray( coord, c * 3 );
  1284. cb.subVectors( vC, vB );
  1285. ab.subVectors( vA, vB );
  1286. cb.cross( ab );
  1287. cb.normalize();
  1288. face.normal.copy( cb );
  1289. if ( vertexNormals[ a ] === undefined ) vertexNormals[ a ] = [];
  1290. if ( vertexNormals[ b ] === undefined ) vertexNormals[ b ] = [];
  1291. if ( vertexNormals[ c ] === undefined ) vertexNormals[ c ] = [];
  1292. vertexNormals[ a ].push( face.normal );
  1293. vertexNormals[ b ].push( face.normal );
  1294. vertexNormals[ c ].push( face.normal );
  1295. faces.push( face );
  1296. }
  1297. // compute vertex normals and build final geometry
  1298. var normals = [];
  1299. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  1300. var face = faces[ i ];
  1301. var nA = weightedNormal( vertexNormals[ face.a ], face.normal, creaseAngle );
  1302. var nB = weightedNormal( vertexNormals[ face.b ], face.normal, creaseAngle );
  1303. var nC = weightedNormal( vertexNormals[ face.c ], face.normal, creaseAngle );
  1304. vA.fromArray( coord, face.a * 3 );
  1305. vB.fromArray( coord, face.b * 3 );
  1306. vC.fromArray( coord, face.c * 3 );
  1307. normals.push( nA.x, nA.y, nA.z );
  1308. normals.push( nB.x, nB.y, nB.z );
  1309. normals.push( nC.x, nC.y, nC.z );
  1310. }
  1311. return new THREE.Float32BufferAttribute( normals, 3 );
  1312. }
  1313. function weightedNormal( normals, vector, creaseAngle ) {
  1314. var normal = new THREE.Vector3();
  1315. if ( creaseAngle === 0 ) {
  1316. normal.copy( vector );
  1317. } else {
  1318. for ( var i = 0, l = normals.length; i < l; i ++ ) {
  1319. if ( normals[ i ].angleTo( vector ) < creaseAngle ) {
  1320. normal.add( normals[ i ] );
  1321. }
  1322. }
  1323. }
  1324. return normal.normalize();
  1325. }
  1326. function toColorArray( colors ) {
  1327. var array = [];
  1328. for ( var i = 0, l = colors.length; i < l; i += 3 ) {
  1329. array.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  1330. }
  1331. return array;
  1332. }
  1333. /**
  1334. * Vertically paints the faces interpolating between the
  1335. * specified colors at the specified angels. This is used for the Background
  1336. * node, but could be applied to other nodes with multiple faces as well.
  1337. *
  1338. * When used with the Background node, default is directionIsDown is true if
  1339. * interpolating the skyColor down from the Zenith. When interpolationg up from
  1340. * the Nadir i.e. interpolating the groundColor, the directionIsDown is false.
  1341. *
  1342. * The first angle is never specified, it is the Zenith (0 rad). Angles are specified
  1343. * in radians. The geometry is thought a sphere, but could be anything. The color interpolation
  1344. * is linear along the Y axis in any case.
  1345. *
  1346. * You must specify one more color than you have angles at the beginning of the colors array.
  1347. * This is the color of the Zenith (the top of the shape).
  1348. *
  1349. * @param {BufferGeometry} geometry
  1350. * @param {number} radius
  1351. * @param {array} angles
  1352. * @param {array} colors
  1353. * @param {boolean} topDown - Whether to work top down or bottom up.
  1354. */
  1355. function paintFaces( geometry, radius, angles, colors, topDown ) {
  1356. var direction = ( topDown === true ) ? 1 : - 1;
  1357. var coord = [], A = {}, B = {}, applyColor = false;
  1358. for ( var k = 0; k < angles.length; k ++ ) {
  1359. // push the vector at which the color changes
  1360. var vec = {
  1361. x: direction * ( Math.cos( angles[ k ] ) * radius ),
  1362. y: direction * ( Math.sin( angles[ k ] ) * radius )
  1363. };
  1364. coord.push( vec );
  1365. }
  1366. var index = geometry.index;
  1367. var positionAttribute = geometry.attributes.position;
  1368. var colorAttribute = new THREE.BufferAttribute( new Float32Array( geometry.attributes.position.count * 3 ), 3 );
  1369. var position = new THREE.Vector3();
  1370. var color = new THREE.Color();
  1371. for ( var i = 0; i < index.count; i ++ ) {
  1372. var vertexIndex = index.getX( i );
  1373. position.fromBufferAttribute( positionAttribute, vertexIndex );
  1374. for ( var j = 0; j < colors.length; j ++ ) {
  1375. // linear interpolation between aColor and bColor, calculate proportion
  1376. // A is previous point (angle)
  1377. if ( j === 0 ) {
  1378. A.x = 0;
  1379. A.y = ( topDown === true ) ? radius : - 1 * radius;
  1380. } else {
  1381. A.x = coord[ j - 1 ].x;
  1382. A.y = coord[ j - 1 ].y;
  1383. }
  1384. // B is current point (angle)
  1385. B = coord[ j ];
  1386. if ( B !== undefined ) {
  1387. // p has to be between the points A and B which we interpolate
  1388. applyColor = ( topDown === true ) ? ( position.y <= A.y && position.y > B.y ) : ( position.y >= A.y && position.y < B.y );
  1389. if ( applyColor === true ) {
  1390. var aColor = colors[ j ];
  1391. var bColor = colors[ j + 1 ];
  1392. // below is simple linear interpolation
  1393. var t = Math.abs( position.y - A.y ) / ( A.y - B.y );
  1394. // to make it faster, you can only calculate this if the y coord changes, the color is the same for points with the same y
  1395. color.copy( aColor ).lerp( bColor, t );
  1396. colorAttribute.setXYZ( vertexIndex, color.r, color.g, color.b );
  1397. } else {
  1398. var colorIndex = ( topDown === true ) ? colors.length - 1 : 0;
  1399. var c = colors[ colorIndex ];
  1400. colorAttribute.setXYZ( vertexIndex, c.r, c.g, c.b );
  1401. }
  1402. }
  1403. }
  1404. }
  1405. geometry.addAttribute( 'color', colorAttribute );
  1406. }
  1407. //
  1408. var textureLoader = new THREE.TextureLoader( this.manager );
  1409. textureLoader.setPath( this.resourcePath || path ).setCrossOrigin( this.crossOrigin );
  1410. // create JSON representing the tree structure of the VRML asset
  1411. var tree = generateVRMLTree( data );
  1412. // check version (only 2.0 is supported)
  1413. if ( tree.version.indexOf( 'V2.0' ) === - 1 ) {
  1414. throw Error( 'THREE.VRMLLexer: Version of VRML asset not supported.' );
  1415. }
  1416. // parse the tree structure to a three.js scene
  1417. var scene = parseTree( tree );
  1418. return scene;
  1419. }
  1420. } );
  1421. function VRMLLexer( tokens ) {
  1422. this.lexer = new chevrotain.Lexer( tokens );
  1423. }
  1424. VRMLLexer.prototype = {
  1425. constructor: VRMLLexer,
  1426. lex: function ( inputText ) {
  1427. var lexingResult = this.lexer.tokenize( inputText );
  1428. if ( lexingResult.errors.length > 0 ) {
  1429. console.error( lexingResult.errors );
  1430. throw Error( 'THREE.VRMLLexer: Lexing errors detected.' );
  1431. }
  1432. return lexingResult;
  1433. }
  1434. };
  1435. function VRMLParser( tokenVocabulary ) {
  1436. chevrotain.Parser.call( this, tokenVocabulary );
  1437. var $ = this;
  1438. var Version = tokenVocabulary[ 'Version' ];
  1439. var LCurly = tokenVocabulary[ 'LCurly' ];
  1440. var RCurly = tokenVocabulary[ 'RCurly' ];
  1441. var LSquare = tokenVocabulary[ 'LSquare' ];
  1442. var RSquare = tokenVocabulary[ 'RSquare' ];
  1443. var Identifier = tokenVocabulary[ 'Identifier' ];
  1444. var RouteIdentifier = tokenVocabulary[ 'RouteIdentifier' ];
  1445. var StringLiteral = tokenVocabulary[ 'StringLiteral' ];
  1446. var NumberLiteral = tokenVocabulary[ 'NumberLiteral' ];
  1447. var TrueLiteral = tokenVocabulary[ 'TrueLiteral' ];
  1448. var FalseLiteral = tokenVocabulary[ 'FalseLiteral' ];
  1449. var NullLiteral = tokenVocabulary[ 'NullLiteral' ];
  1450. var DEF = tokenVocabulary[ 'DEF' ];
  1451. var USE = tokenVocabulary[ 'USE' ];
  1452. var ROUTE = tokenVocabulary[ 'ROUTE' ];
  1453. var TO = tokenVocabulary[ 'TO' ];
  1454. var NodeName = tokenVocabulary[ 'NodeName' ];
  1455. $.RULE( 'vrml', function () {
  1456. $.SUBRULE( $.version );
  1457. $.AT_LEAST_ONE( function () {
  1458. $.SUBRULE( $.node );
  1459. } );
  1460. $.MANY( function () {
  1461. $.SUBRULE( $.route );
  1462. } );
  1463. } );
  1464. $.RULE( 'version', function () {
  1465. $.CONSUME( Version );
  1466. } );
  1467. $.RULE( 'node', function () {
  1468. $.OPTION( function () {
  1469. $.SUBRULE( $.def );
  1470. } );
  1471. $.CONSUME( NodeName );
  1472. $.CONSUME( LCurly );
  1473. $.MANY( function () {
  1474. $.SUBRULE( $.field );
  1475. } );
  1476. $.CONSUME( RCurly );
  1477. } );
  1478. $.RULE( 'field', function () {
  1479. $.CONSUME( Identifier );
  1480. $.OR2( [
  1481. { ALT: function () {
  1482. $.SUBRULE( $.singleFieldValue );
  1483. } },
  1484. { ALT: function () {
  1485. $.SUBRULE( $.multiFieldValue );
  1486. } }
  1487. ] );
  1488. } );
  1489. $.RULE( 'def', function () {
  1490. $.CONSUME( DEF );
  1491. $.CONSUME( Identifier );
  1492. } );
  1493. $.RULE( 'use', function () {
  1494. $.CONSUME( USE );
  1495. $.CONSUME( Identifier );
  1496. } );
  1497. $.RULE( 'singleFieldValue', function () {
  1498. $.AT_LEAST_ONE( function () {
  1499. $.OR( [
  1500. { ALT: function () {
  1501. $.SUBRULE( $.node );
  1502. } },
  1503. { ALT: function () {
  1504. $.SUBRULE( $.use );
  1505. } },
  1506. { ALT: function () {
  1507. $.CONSUME( StringLiteral );
  1508. } },
  1509. { ALT: function () {
  1510. $.CONSUME( NumberLiteral );
  1511. } },
  1512. { ALT: function () {
  1513. $.CONSUME( TrueLiteral );
  1514. } },
  1515. { ALT: function () {
  1516. $.CONSUME( FalseLiteral );
  1517. } },
  1518. { ALT: function () {
  1519. $.CONSUME( NullLiteral );
  1520. } }
  1521. ] );
  1522. } );
  1523. } );
  1524. $.RULE( 'multiFieldValue', function () {
  1525. $.CONSUME( LSquare );
  1526. $.MANY( function () {
  1527. $.OR( [
  1528. { ALT: function () {
  1529. $.SUBRULE( $.node );
  1530. } },
  1531. { ALT: function () {
  1532. $.SUBRULE( $.use );
  1533. } },
  1534. { ALT: function () {
  1535. $.CONSUME( StringLiteral );
  1536. } },
  1537. { ALT: function () {
  1538. $.CONSUME( NumberLiteral );
  1539. } },
  1540. { ALT: function () {
  1541. $.CONSUME( NullLiteral );
  1542. } }
  1543. ] );
  1544. } );
  1545. $.CONSUME( RSquare );
  1546. } );
  1547. $.RULE( 'route', function () {
  1548. $.CONSUME( ROUTE );
  1549. $.CONSUME( RouteIdentifier );
  1550. $.CONSUME( TO );
  1551. $.CONSUME2( RouteIdentifier );
  1552. } );
  1553. this.performSelfAnalysis();
  1554. }
  1555. VRMLParser.prototype = Object.create( chevrotain.Parser.prototype );
  1556. VRMLParser.prototype.constructor = VRMLParser;
  1557. function Face( a, b, c ) {
  1558. this.a = a;
  1559. this.b = b;
  1560. this.c = c;
  1561. this.normal = new THREE.Vector3();
  1562. }
  1563. return VRMLLoader;
  1564. } )();