@anov/3d 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (570) hide show
  1. package/README.md +142 -1
  2. package/dist/core/camera.d.ts +31 -4
  3. package/dist/core/camera.js +62 -52
  4. package/dist/core/control/transformControls.d.ts +12 -0
  5. package/dist/core/control/transformControls.js +72 -0
  6. package/dist/core/cssRenderer.d.ts +17 -0
  7. package/dist/core/cssRenderer.js +36 -0
  8. package/dist/core/global/global.d.ts +27 -0
  9. package/dist/core/global/global.js +72 -0
  10. package/dist/core/global/globalControl.d.ts +17 -0
  11. package/dist/core/global/globalControl.js +62 -0
  12. package/dist/core/group.d.ts +51 -6
  13. package/dist/core/group.js +124 -16
  14. package/dist/core/line.d.ts +13 -0
  15. package/dist/core/line.js +83 -0
  16. package/dist/core/mesh.d.ts +12 -7
  17. package/dist/core/mesh.js +57 -56
  18. package/dist/core/model.d.ts +11 -3
  19. package/dist/core/model.js +34 -7
  20. package/dist/core/scene.d.ts +84 -25
  21. package/dist/core/scene.js +207 -53
  22. package/dist/core/use/useScene.d.ts +10 -0
  23. package/dist/core/use/useScene.js +14 -0
  24. package/dist/core/use/useframe.d.ts +6 -0
  25. package/dist/core/use/useframe.js +11 -0
  26. package/dist/export.d.ts +41 -0
  27. package/dist/export.js +37 -0
  28. package/dist/index.d.ts +3 -6
  29. package/dist/index.js +5 -6
  30. package/dist/threeCell.d.ts +8 -0
  31. package/dist/threeCell.js +16 -0
  32. package/dist/type.d.ts +4 -3
  33. package/dist/utils/createElement.d.ts +103 -0
  34. package/dist/utils/createElement.js +145 -0
  35. package/dist/utils/createLabel.d.ts +2 -0
  36. package/dist/utils/createLabel.js +4 -0
  37. package/dist/utils/index.d.ts +36 -0
  38. package/dist/utils/index.js +76 -0
  39. package/dist/utils/line.d.ts +0 -0
  40. package/dist/utils/line.js +0 -0
  41. package/dist/utils/move.d.ts +48 -0
  42. package/dist/utils/move.js +149 -0
  43. package/examples/fonts/LICENSE +13 -0
  44. package/examples/fonts/README.md +11 -0
  45. package/examples/fonts/droid/NOTICE +190 -0
  46. package/examples/fonts/droid/README.txt +18 -0
  47. package/examples/fonts/droid/droid_sans_bold.typeface.json +1 -0
  48. package/examples/fonts/droid/droid_sans_mono_regular.typeface.json +1 -0
  49. package/examples/fonts/droid/droid_sans_regular.typeface.json +1 -0
  50. package/examples/fonts/droid/droid_serif_bold.typeface.json +1 -0
  51. package/examples/fonts/droid/droid_serif_regular.typeface.json +1 -0
  52. package/examples/fonts/gentilis_bold.typeface.json +1 -0
  53. package/examples/fonts/gentilis_regular.typeface.json +1 -0
  54. package/examples/fonts/helvetiker_bold.typeface.json +1 -0
  55. package/examples/fonts/helvetiker_regular.typeface.json +1 -0
  56. package/examples/fonts/optimer_bold.typeface.json +1 -0
  57. package/examples/fonts/optimer_regular.typeface.json +1 -0
  58. package/examples/fonts/ttf/README.md +9 -0
  59. package/examples/fonts/ttf/kenpixel.ttf +0 -0
  60. package/examples/jsm/animation/AnimationClipCreator.js +116 -0
  61. package/examples/jsm/animation/CCDIKSolver.js +482 -0
  62. package/examples/jsm/animation/MMDAnimationHelper.js +1207 -0
  63. package/examples/jsm/animation/MMDPhysics.js +1406 -0
  64. package/examples/jsm/cameras/CinematicCamera.js +208 -0
  65. package/examples/jsm/capabilities/WebGL.js +91 -0
  66. package/examples/jsm/capabilities/WebGPU.js +53 -0
  67. package/examples/jsm/controls/ArcballControls.js +3224 -0
  68. package/examples/jsm/controls/DragControls.js +220 -0
  69. package/examples/jsm/controls/FirstPersonControls.js +325 -0
  70. package/examples/jsm/controls/FlyControls.js +300 -0
  71. package/examples/jsm/controls/MapControls.js +28 -0
  72. package/examples/jsm/controls/OrbitControls.js +1388 -0
  73. package/examples/jsm/controls/PointerLockControls.js +162 -0
  74. package/examples/jsm/controls/TrackballControls.js +828 -0
  75. package/examples/jsm/controls/TransformControls.js +1557 -0
  76. package/examples/jsm/csm/CSM.js +384 -0
  77. package/examples/jsm/csm/CSMFrustum.js +152 -0
  78. package/examples/jsm/csm/CSMHelper.js +193 -0
  79. package/examples/jsm/csm/CSMShader.js +252 -0
  80. package/examples/jsm/curves/CurveExtras.js +422 -0
  81. package/examples/jsm/curves/NURBSCurve.js +80 -0
  82. package/examples/jsm/curves/NURBSSurface.js +52 -0
  83. package/examples/jsm/curves/NURBSUtils.js +487 -0
  84. package/examples/jsm/effects/AnaglyphEffect.js +154 -0
  85. package/examples/jsm/effects/AsciiEffect.js +263 -0
  86. package/examples/jsm/effects/OutlineEffect.js +539 -0
  87. package/examples/jsm/effects/ParallaxBarrierEffect.js +119 -0
  88. package/examples/jsm/effects/PeppersGhostEffect.js +153 -0
  89. package/examples/jsm/effects/StereoEffect.js +55 -0
  90. package/examples/jsm/environments/DebugEnvironment.js +52 -0
  91. package/examples/jsm/environments/RoomEnvironment.js +148 -0
  92. package/examples/jsm/exporters/DRACOExporter.js +267 -0
  93. package/examples/jsm/exporters/EXRExporter.js +501 -0
  94. package/examples/jsm/exporters/GLTFExporter.js +3161 -0
  95. package/examples/jsm/exporters/KTX2Exporter.js +292 -0
  96. package/examples/jsm/exporters/MMDExporter.js +217 -0
  97. package/examples/jsm/exporters/OBJExporter.js +284 -0
  98. package/examples/jsm/exporters/PLYExporter.js +528 -0
  99. package/examples/jsm/exporters/STLExporter.js +199 -0
  100. package/examples/jsm/exporters/USDZExporter.js +711 -0
  101. package/examples/jsm/geometries/BoxLineGeometry.js +69 -0
  102. package/examples/jsm/geometries/ConvexGeometry.js +53 -0
  103. package/examples/jsm/geometries/DecalGeometry.js +356 -0
  104. package/examples/jsm/geometries/ParametricGeometries.js +254 -0
  105. package/examples/jsm/geometries/ParametricGeometry.js +139 -0
  106. package/examples/jsm/geometries/RoundedBoxGeometry.js +155 -0
  107. package/examples/jsm/geometries/TeapotGeometry.js +704 -0
  108. package/examples/jsm/geometries/TextGeometry.js +57 -0
  109. package/examples/jsm/helpers/LightProbeHelper.js +130 -0
  110. package/examples/jsm/helpers/OctreeHelper.js +73 -0
  111. package/examples/jsm/helpers/PositionalAudioHelper.js +109 -0
  112. package/examples/jsm/helpers/RectAreaLightHelper.js +85 -0
  113. package/examples/jsm/helpers/VertexNormalsHelper.js +96 -0
  114. package/examples/jsm/helpers/VertexTangentsHelper.js +88 -0
  115. package/examples/jsm/helpers/ViewHelper.js +333 -0
  116. package/examples/jsm/interactive/HTMLMesh.js +565 -0
  117. package/examples/jsm/interactive/InteractiveGroup.js +116 -0
  118. package/examples/jsm/interactive/SelectionBox.js +227 -0
  119. package/examples/jsm/interactive/SelectionHelper.js +104 -0
  120. package/examples/jsm/libs/ammo.wasm.js +822 -0
  121. package/examples/jsm/libs/ammo.wasm.wasm +0 -0
  122. package/examples/jsm/libs/basis/README.md +46 -0
  123. package/examples/jsm/libs/basis/basis_transcoder.js +21 -0
  124. package/examples/jsm/libs/basis/basis_transcoder.wasm +0 -0
  125. package/examples/jsm/libs/chevrotain.module.min.js +141 -0
  126. package/examples/jsm/libs/draco/README.md +32 -0
  127. package/examples/jsm/libs/draco/draco_decoder.js +34 -0
  128. package/examples/jsm/libs/draco/draco_decoder.wasm +0 -0
  129. package/examples/jsm/libs/draco/draco_encoder.js +33 -0
  130. package/examples/jsm/libs/draco/draco_wasm_wrapper.js +117 -0
  131. package/examples/jsm/libs/draco/gltf/draco_decoder.js +33 -0
  132. package/examples/jsm/libs/draco/gltf/draco_decoder.wasm +0 -0
  133. package/examples/jsm/libs/draco/gltf/draco_encoder.js +33 -0
  134. package/examples/jsm/libs/draco/gltf/draco_wasm_wrapper.js +116 -0
  135. package/examples/jsm/libs/ecsy.module.js +1792 -0
  136. package/examples/jsm/libs/fflate.module.js +2474 -0
  137. package/examples/jsm/libs/ktx-parse.module.js +1 -0
  138. package/examples/jsm/libs/lil-gui.module.min.js +8 -0
  139. package/examples/jsm/libs/lottie_canvas.module.js +14844 -0
  140. package/examples/jsm/libs/meshopt_decoder.module.js +178 -0
  141. package/examples/jsm/libs/mikktspace.module.js +128 -0
  142. package/examples/jsm/libs/mmdparser.module.js +11530 -0
  143. package/examples/jsm/libs/motion-controllers.module.js +397 -0
  144. package/examples/jsm/libs/opentype.module.js +14568 -0
  145. package/examples/jsm/libs/potpack.module.js +125 -0
  146. package/examples/jsm/libs/rhino3dm/rhino3dm.js +21 -0
  147. package/examples/jsm/libs/rhino3dm/rhino3dm.module.js +16 -0
  148. package/examples/jsm/libs/rhino3dm/rhino3dm.wasm +0 -0
  149. package/examples/jsm/libs/stats.module.js +167 -0
  150. package/examples/jsm/libs/tween.module.js +803 -0
  151. package/examples/jsm/libs/utif.module.js +1579 -0
  152. package/examples/jsm/libs/zstddec.module.js +1 -0
  153. package/examples/jsm/lights/IESSpotLight.js +25 -0
  154. package/examples/jsm/lights/LightProbeGenerator.js +252 -0
  155. package/examples/jsm/lights/RectAreaLightUniformsLib.js +79 -0
  156. package/examples/jsm/lines/Line2.js +19 -0
  157. package/examples/jsm/lines/LineGeometry.js +79 -0
  158. package/examples/jsm/lines/LineMaterial.js +702 -0
  159. package/examples/jsm/lines/LineSegments2.js +361 -0
  160. package/examples/jsm/lines/LineSegmentsGeometry.js +241 -0
  161. package/examples/jsm/lines/Wireframe.js +56 -0
  162. package/examples/jsm/lines/WireframeGeometry2.js +24 -0
  163. package/examples/jsm/loaders/3DMLoader.js +1497 -0
  164. package/examples/jsm/loaders/3MFLoader.js +1478 -0
  165. package/examples/jsm/loaders/AMFLoader.js +521 -0
  166. package/examples/jsm/loaders/BVHLoader.js +437 -0
  167. package/examples/jsm/loaders/ColladaLoader.js +4122 -0
  168. package/examples/jsm/loaders/DDSLoader.js +274 -0
  169. package/examples/jsm/loaders/DRACOLoader.js +612 -0
  170. package/examples/jsm/loaders/EXRLoader.js +2309 -0
  171. package/examples/jsm/loaders/FBXLoader.js +4142 -0
  172. package/examples/jsm/loaders/FontLoader.js +183 -0
  173. package/examples/jsm/loaders/GCodeLoader.js +261 -0
  174. package/examples/jsm/loaders/GLTFLoader.js +4576 -0
  175. package/examples/jsm/loaders/HDRCubeTextureLoader.js +115 -0
  176. package/examples/jsm/loaders/IESLoader.js +337 -0
  177. package/examples/jsm/loaders/KMZLoader.js +130 -0
  178. package/examples/jsm/loaders/KTX2Loader.js +868 -0
  179. package/examples/jsm/loaders/KTXLoader.js +176 -0
  180. package/examples/jsm/loaders/LDrawLoader.js +2464 -0
  181. package/examples/jsm/loaders/LUT3dlLoader.js +151 -0
  182. package/examples/jsm/loaders/LUTCubeLoader.js +153 -0
  183. package/examples/jsm/loaders/LWOLoader.js +1052 -0
  184. package/examples/jsm/loaders/LogLuvLoader.js +606 -0
  185. package/examples/jsm/loaders/LottieLoader.js +77 -0
  186. package/examples/jsm/loaders/MD2Loader.js +399 -0
  187. package/examples/jsm/loaders/MDDLoader.js +102 -0
  188. package/examples/jsm/loaders/MMDLoader.js +2273 -0
  189. package/examples/jsm/loaders/MTLLoader.js +567 -0
  190. package/examples/jsm/loaders/MaterialXLoader.js +734 -0
  191. package/examples/jsm/loaders/NRRDLoader.js +699 -0
  192. package/examples/jsm/loaders/OBJLoader.js +905 -0
  193. package/examples/jsm/loaders/PCDLoader.js +467 -0
  194. package/examples/jsm/loaders/PDBLoader.js +232 -0
  195. package/examples/jsm/loaders/PLYLoader.js +771 -0
  196. package/examples/jsm/loaders/PVRLoader.js +251 -0
  197. package/examples/jsm/loaders/RGBELoader.js +468 -0
  198. package/examples/jsm/loaders/RGBMLoader.js +1065 -0
  199. package/examples/jsm/loaders/STLLoader.js +403 -0
  200. package/examples/jsm/loaders/SVGLoader.js +3172 -0
  201. package/examples/jsm/loaders/TDSLoader.js +1124 -0
  202. package/examples/jsm/loaders/TGALoader.js +517 -0
  203. package/examples/jsm/loaders/TIFFLoader.js +36 -0
  204. package/examples/jsm/loaders/TTFLoader.js +214 -0
  205. package/examples/jsm/loaders/TiltLoader.js +520 -0
  206. package/examples/jsm/loaders/USDZLoader.js +633 -0
  207. package/examples/jsm/loaders/VOXLoader.js +311 -0
  208. package/examples/jsm/loaders/VRMLLoader.js +3533 -0
  209. package/examples/jsm/loaders/VTKLoader.js +1163 -0
  210. package/examples/jsm/loaders/XYZLoader.js +106 -0
  211. package/examples/jsm/loaders/lwo/IFFParser.js +1218 -0
  212. package/examples/jsm/loaders/lwo/LWO2Parser.js +414 -0
  213. package/examples/jsm/loaders/lwo/LWO3Parser.js +373 -0
  214. package/examples/jsm/materials/MeshGouraudMaterial.js +420 -0
  215. package/examples/jsm/math/Capsule.js +137 -0
  216. package/examples/jsm/math/ColorConverter.js +36 -0
  217. package/examples/jsm/math/ConvexHull.js +1271 -0
  218. package/examples/jsm/math/ImprovedNoise.js +71 -0
  219. package/examples/jsm/math/Lut.js +204 -0
  220. package/examples/jsm/math/MeshSurfaceSampler.js +250 -0
  221. package/examples/jsm/math/OBB.js +423 -0
  222. package/examples/jsm/math/Octree.js +462 -0
  223. package/examples/jsm/math/SimplexNoise.js +444 -0
  224. package/examples/jsm/misc/ConvexObjectBreaker.js +519 -0
  225. package/examples/jsm/misc/GPUComputationRenderer.js +446 -0
  226. package/examples/jsm/misc/Gyroscope.js +66 -0
  227. package/examples/jsm/misc/MD2Character.js +276 -0
  228. package/examples/jsm/misc/MD2CharacterComplex.js +576 -0
  229. package/examples/jsm/misc/MorphAnimMesh.js +75 -0
  230. package/examples/jsm/misc/MorphBlendMesh.js +322 -0
  231. package/examples/jsm/misc/ProgressiveLightMap.js +323 -0
  232. package/examples/jsm/misc/RollerCoaster.js +566 -0
  233. package/examples/jsm/misc/TubePainter.js +205 -0
  234. package/examples/jsm/misc/Volume.js +473 -0
  235. package/examples/jsm/misc/VolumeSlice.js +229 -0
  236. package/examples/jsm/modifiers/CurveModifier.js +326 -0
  237. package/examples/jsm/modifiers/EdgeSplitModifier.js +279 -0
  238. package/examples/jsm/modifiers/SimplifyModifier.js +525 -0
  239. package/examples/jsm/modifiers/TessellateModifier.js +307 -0
  240. package/examples/jsm/nodes/Nodes.js +171 -0
  241. package/examples/jsm/nodes/accessors/BitangentNode.js +89 -0
  242. package/examples/jsm/nodes/accessors/BufferAttributeNode.js +99 -0
  243. package/examples/jsm/nodes/accessors/BufferNode.js +30 -0
  244. package/examples/jsm/nodes/accessors/CameraNode.js +98 -0
  245. package/examples/jsm/nodes/accessors/CubeTextureNode.js +103 -0
  246. package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +77 -0
  247. package/examples/jsm/nodes/accessors/InstanceNode.js +71 -0
  248. package/examples/jsm/nodes/accessors/MaterialNode.js +267 -0
  249. package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +39 -0
  250. package/examples/jsm/nodes/accessors/ModelNode.js +34 -0
  251. package/examples/jsm/nodes/accessors/ModelViewProjectionNode.js +29 -0
  252. package/examples/jsm/nodes/accessors/MorphNode.js +70 -0
  253. package/examples/jsm/nodes/accessors/NormalNode.js +96 -0
  254. package/examples/jsm/nodes/accessors/Object3DNode.js +150 -0
  255. package/examples/jsm/nodes/accessors/PointUVNode.js +26 -0
  256. package/examples/jsm/nodes/accessors/PositionNode.js +104 -0
  257. package/examples/jsm/nodes/accessors/ReferenceNode.js +72 -0
  258. package/examples/jsm/nodes/accessors/ReflectVectorNode.js +35 -0
  259. package/examples/jsm/nodes/accessors/SceneNode.js +52 -0
  260. package/examples/jsm/nodes/accessors/SkinningNode.js +93 -0
  261. package/examples/jsm/nodes/accessors/StorageBufferNode.js +27 -0
  262. package/examples/jsm/nodes/accessors/TangentNode.js +103 -0
  263. package/examples/jsm/nodes/accessors/TextureBicubicNode.js +94 -0
  264. package/examples/jsm/nodes/accessors/TextureNode.js +271 -0
  265. package/examples/jsm/nodes/accessors/TextureSizeNode.js +35 -0
  266. package/examples/jsm/nodes/accessors/UVNode.js +47 -0
  267. package/examples/jsm/nodes/accessors/UserDataNode.js +29 -0
  268. package/examples/jsm/nodes/code/CodeNode.js +78 -0
  269. package/examples/jsm/nodes/code/ExpressionNode.js +37 -0
  270. package/examples/jsm/nodes/code/FunctionCallNode.js +96 -0
  271. package/examples/jsm/nodes/code/FunctionNode.js +127 -0
  272. package/examples/jsm/nodes/code/ScriptableNode.js +488 -0
  273. package/examples/jsm/nodes/code/ScriptableValueNode.js +167 -0
  274. package/examples/jsm/nodes/core/ArrayUniformNode.js +26 -0
  275. package/examples/jsm/nodes/core/AttributeNode.js +102 -0
  276. package/examples/jsm/nodes/core/BypassNode.js +45 -0
  277. package/examples/jsm/nodes/core/CacheNode.js +46 -0
  278. package/examples/jsm/nodes/core/ConstNode.js +32 -0
  279. package/examples/jsm/nodes/core/ContextNode.js +61 -0
  280. package/examples/jsm/nodes/core/IndexNode.js +66 -0
  281. package/examples/jsm/nodes/core/InputNode.js +83 -0
  282. package/examples/jsm/nodes/core/LightingModel.js +15 -0
  283. package/examples/jsm/nodes/core/Node.js +454 -0
  284. package/examples/jsm/nodes/core/NodeAttribute.js +15 -0
  285. package/examples/jsm/nodes/core/NodeBuilder.js +1016 -0
  286. package/examples/jsm/nodes/core/NodeCache.js +26 -0
  287. package/examples/jsm/nodes/core/NodeCode.js +15 -0
  288. package/examples/jsm/nodes/core/NodeFrame.js +110 -0
  289. package/examples/jsm/nodes/core/NodeFunction.js +22 -0
  290. package/examples/jsm/nodes/core/NodeFunctionInput.js +17 -0
  291. package/examples/jsm/nodes/core/NodeKeywords.js +80 -0
  292. package/examples/jsm/nodes/core/NodeParser.js +11 -0
  293. package/examples/jsm/nodes/core/NodeUniform.js +28 -0
  294. package/examples/jsm/nodes/core/NodeUtils.js +212 -0
  295. package/examples/jsm/nodes/core/NodeVar.js +14 -0
  296. package/examples/jsm/nodes/core/NodeVarying.js +17 -0
  297. package/examples/jsm/nodes/core/PropertyNode.js +61 -0
  298. package/examples/jsm/nodes/core/StackNode.js +99 -0
  299. package/examples/jsm/nodes/core/TempNode.js +58 -0
  300. package/examples/jsm/nodes/core/UniformNode.js +61 -0
  301. package/examples/jsm/nodes/core/VarNode.js +87 -0
  302. package/examples/jsm/nodes/core/VaryingNode.js +69 -0
  303. package/examples/jsm/nodes/core/constants.js +27 -0
  304. package/examples/jsm/nodes/display/BlendModeNode.js +99 -0
  305. package/examples/jsm/nodes/display/BumpMapNode.js +77 -0
  306. package/examples/jsm/nodes/display/ColorAdjustmentNode.js +100 -0
  307. package/examples/jsm/nodes/display/ColorSpaceNode.js +108 -0
  308. package/examples/jsm/nodes/display/FrontFacingNode.js +27 -0
  309. package/examples/jsm/nodes/display/NormalMapNode.js +106 -0
  310. package/examples/jsm/nodes/display/PosterizeNode.js +32 -0
  311. package/examples/jsm/nodes/display/ToneMappingNode.js +141 -0
  312. package/examples/jsm/nodes/display/ViewportDepthNode.js +69 -0
  313. package/examples/jsm/nodes/display/ViewportDepthTextureNode.js +34 -0
  314. package/examples/jsm/nodes/display/ViewportNode.js +115 -0
  315. package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +31 -0
  316. package/examples/jsm/nodes/display/ViewportTextureNode.js +75 -0
  317. package/examples/jsm/nodes/fog/FogExp2Node.js +35 -0
  318. package/examples/jsm/nodes/fog/FogNode.js +37 -0
  319. package/examples/jsm/nodes/fog/FogRangeNode.js +34 -0
  320. package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +40 -0
  321. package/examples/jsm/nodes/functions/BSDF/BRDF_Lambert.js +9 -0
  322. package/examples/jsm/nodes/functions/BSDF/BRDF_Sheen.js +43 -0
  323. package/examples/jsm/nodes/functions/BSDF/DFGApprox.js +29 -0
  324. package/examples/jsm/nodes/functions/BSDF/D_GGX.js +18 -0
  325. package/examples/jsm/nodes/functions/BSDF/EnvironmentBRDF.js +13 -0
  326. package/examples/jsm/nodes/functions/BSDF/F_Schlick.js +16 -0
  327. package/examples/jsm/nodes/functions/BSDF/Schlick_to_F0.js +13 -0
  328. package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +20 -0
  329. package/examples/jsm/nodes/functions/PhongLightingModel.js +67 -0
  330. package/examples/jsm/nodes/functions/PhysicalLightingModel.js +343 -0
  331. package/examples/jsm/nodes/functions/material/getGeometryRoughness.js +13 -0
  332. package/examples/jsm/nodes/functions/material/getRoughness.js +18 -0
  333. package/examples/jsm/nodes/geometry/RangeNode.js +104 -0
  334. package/examples/jsm/nodes/gpgpu/ComputeNode.js +85 -0
  335. package/examples/jsm/nodes/lighting/AONode.js +27 -0
  336. package/examples/jsm/nodes/lighting/AmbientLightNode.js +27 -0
  337. package/examples/jsm/nodes/lighting/AnalyticLightNode.js +184 -0
  338. package/examples/jsm/nodes/lighting/DirectionalLightNode.js +40 -0
  339. package/examples/jsm/nodes/lighting/EnvironmentNode.js +191 -0
  340. package/examples/jsm/nodes/lighting/HemisphereLightNode.js +55 -0
  341. package/examples/jsm/nodes/lighting/IESSpotLightNode.js +39 -0
  342. package/examples/jsm/nodes/lighting/LightNode.js +57 -0
  343. package/examples/jsm/nodes/lighting/LightUtils.js +17 -0
  344. package/examples/jsm/nodes/lighting/LightingContextNode.js +102 -0
  345. package/examples/jsm/nodes/lighting/LightingNode.js +21 -0
  346. package/examples/jsm/nodes/lighting/LightsNode.js +128 -0
  347. package/examples/jsm/nodes/lighting/PointLightNode.js +68 -0
  348. package/examples/jsm/nodes/lighting/SpotLightNode.js +89 -0
  349. package/examples/jsm/nodes/loaders/NodeLoader.js +108 -0
  350. package/examples/jsm/nodes/loaders/NodeMaterialLoader.js +59 -0
  351. package/examples/jsm/nodes/loaders/NodeObjectLoader.js +70 -0
  352. package/examples/jsm/nodes/materials/LineBasicNodeMaterial.js +28 -0
  353. package/examples/jsm/nodes/materials/Materials.js +12 -0
  354. package/examples/jsm/nodes/materials/MeshBasicNodeMaterial.js +27 -0
  355. package/examples/jsm/nodes/materials/MeshLambertNodeMaterial.js +34 -0
  356. package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +40 -0
  357. package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +65 -0
  358. package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +128 -0
  359. package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +80 -0
  360. package/examples/jsm/nodes/materials/NodeMaterial.js +536 -0
  361. package/examples/jsm/nodes/materials/PointsNodeMaterial.js +49 -0
  362. package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +103 -0
  363. package/examples/jsm/nodes/materialx/DISCLAIMER.md +199 -0
  364. package/examples/jsm/nodes/materialx/MaterialXNodes.js +68 -0
  365. package/examples/jsm/nodes/materialx/lib/mx_hsv.js +56 -0
  366. package/examples/jsm/nodes/materialx/lib/mx_noise.js +618 -0
  367. package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +19 -0
  368. package/examples/jsm/nodes/math/CondNode.js +86 -0
  369. package/examples/jsm/nodes/math/MathNode.js +359 -0
  370. package/examples/jsm/nodes/math/OperatorNode.js +269 -0
  371. package/examples/jsm/nodes/parsers/GLSLNodeFunction.js +152 -0
  372. package/examples/jsm/nodes/parsers/GLSLNodeParser.js +14 -0
  373. package/examples/jsm/nodes/procedural/CheckerNode.js +42 -0
  374. package/examples/jsm/nodes/shadernode/ShaderNode.js +420 -0
  375. package/examples/jsm/nodes/utils/ArrayElementNode.js +33 -0
  376. package/examples/jsm/nodes/utils/ConvertNode.js +65 -0
  377. package/examples/jsm/nodes/utils/DiscardNode.js +26 -0
  378. package/examples/jsm/nodes/utils/EquirectUVNode.js +33 -0
  379. package/examples/jsm/nodes/utils/JoinNode.js +51 -0
  380. package/examples/jsm/nodes/utils/LoopNode.js +186 -0
  381. package/examples/jsm/nodes/utils/MatcapUVNode.js +30 -0
  382. package/examples/jsm/nodes/utils/MaxMipLevelNode.js +46 -0
  383. package/examples/jsm/nodes/utils/OscNode.js +81 -0
  384. package/examples/jsm/nodes/utils/PackingNode.js +55 -0
  385. package/examples/jsm/nodes/utils/RemapNode.js +42 -0
  386. package/examples/jsm/nodes/utils/RotateUVNode.js +43 -0
  387. package/examples/jsm/nodes/utils/SpecularMIPLevelNode.js +37 -0
  388. package/examples/jsm/nodes/utils/SplitNode.js +104 -0
  389. package/examples/jsm/nodes/utils/SpriteSheetUVNode.js +41 -0
  390. package/examples/jsm/nodes/utils/TimerNode.js +94 -0
  391. package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +62 -0
  392. package/examples/jsm/objects/GroundProjectedSkybox.js +172 -0
  393. package/examples/jsm/objects/Lensflare.js +377 -0
  394. package/examples/jsm/objects/MarchingCubes.js +1176 -0
  395. package/examples/jsm/objects/Reflector.js +264 -0
  396. package/examples/jsm/objects/ReflectorForSSRPass.js +349 -0
  397. package/examples/jsm/objects/Refractor.js +324 -0
  398. package/examples/jsm/objects/ShadowMesh.js +80 -0
  399. package/examples/jsm/objects/Sky.js +219 -0
  400. package/examples/jsm/objects/Water.js +330 -0
  401. package/examples/jsm/objects/Water2.js +358 -0
  402. package/examples/jsm/offscreen/jank.js +45 -0
  403. package/examples/jsm/offscreen/offscreen.js +8 -0
  404. package/examples/jsm/offscreen/scene.js +86 -0
  405. package/examples/jsm/physics/AmmoPhysics.js +285 -0
  406. package/examples/jsm/physics/RapierPhysics.js +199 -0
  407. package/examples/jsm/postprocessing/AfterimagePass.js +104 -0
  408. package/examples/jsm/postprocessing/BloomPass.js +172 -0
  409. package/examples/jsm/postprocessing/BokehPass.js +140 -0
  410. package/examples/jsm/postprocessing/ClearPass.js +46 -0
  411. package/examples/jsm/postprocessing/CubeTexturePass.js +85 -0
  412. package/examples/jsm/postprocessing/DotScreenPass.js +65 -0
  413. package/examples/jsm/postprocessing/EffectComposer.js +231 -0
  414. package/examples/jsm/postprocessing/FilmPass.js +66 -0
  415. package/examples/jsm/postprocessing/GlitchPass.js +128 -0
  416. package/examples/jsm/postprocessing/HalftonePass.js +79 -0
  417. package/examples/jsm/postprocessing/LUTPass.js +173 -0
  418. package/examples/jsm/postprocessing/MaskPass.js +104 -0
  419. package/examples/jsm/postprocessing/OutlinePass.js +654 -0
  420. package/examples/jsm/postprocessing/OutputPass.js +91 -0
  421. package/examples/jsm/postprocessing/Pass.js +84 -0
  422. package/examples/jsm/postprocessing/RenderPass.js +81 -0
  423. package/examples/jsm/postprocessing/RenderPixelatedPass.js +235 -0
  424. package/examples/jsm/postprocessing/SAOPass.js +411 -0
  425. package/examples/jsm/postprocessing/SMAAPass.js +201 -0
  426. package/examples/jsm/postprocessing/SSAARenderPass.js +228 -0
  427. package/examples/jsm/postprocessing/SSAOPass.js +440 -0
  428. package/examples/jsm/postprocessing/SSRPass.js +641 -0
  429. package/examples/jsm/postprocessing/SavePass.js +79 -0
  430. package/examples/jsm/postprocessing/ShaderPass.js +77 -0
  431. package/examples/jsm/postprocessing/TAARenderPass.js +189 -0
  432. package/examples/jsm/postprocessing/TexturePass.js +67 -0
  433. package/examples/jsm/postprocessing/UnrealBloomPass.js +415 -0
  434. package/examples/jsm/renderers/CSS2DRenderer.js +215 -0
  435. package/examples/jsm/renderers/CSS3DRenderer.js +335 -0
  436. package/examples/jsm/renderers/Projector.js +918 -0
  437. package/examples/jsm/renderers/SVGRenderer.js +553 -0
  438. package/examples/jsm/renderers/common/Animation.js +58 -0
  439. package/examples/jsm/renderers/common/Attributes.js +75 -0
  440. package/examples/jsm/renderers/common/Backend.js +162 -0
  441. package/examples/jsm/renderers/common/Background.js +136 -0
  442. package/examples/jsm/renderers/common/Binding.js +19 -0
  443. package/examples/jsm/renderers/common/Bindings.js +165 -0
  444. package/examples/jsm/renderers/common/Buffer.js +38 -0
  445. package/examples/jsm/renderers/common/BufferUtils.js +33 -0
  446. package/examples/jsm/renderers/common/ChainMap.js +89 -0
  447. package/examples/jsm/renderers/common/ComputePipeline.js +17 -0
  448. package/examples/jsm/renderers/common/Constants.js +14 -0
  449. package/examples/jsm/renderers/common/CubeRenderTarget.js +65 -0
  450. package/examples/jsm/renderers/common/DataMap.js +54 -0
  451. package/examples/jsm/renderers/common/Geometries.js +215 -0
  452. package/examples/jsm/renderers/common/Info.js +73 -0
  453. package/examples/jsm/renderers/common/Pipeline.js +13 -0
  454. package/examples/jsm/renderers/common/Pipelines.js +370 -0
  455. package/examples/jsm/renderers/common/ProgrammableStage.js +18 -0
  456. package/examples/jsm/renderers/common/RenderContext.js +38 -0
  457. package/examples/jsm/renderers/common/RenderContexts.js +49 -0
  458. package/examples/jsm/renderers/common/RenderList.js +178 -0
  459. package/examples/jsm/renderers/common/RenderLists.js +38 -0
  460. package/examples/jsm/renderers/common/RenderObject.js +129 -0
  461. package/examples/jsm/renderers/common/RenderObjects.js +95 -0
  462. package/examples/jsm/renderers/common/RenderPipeline.js +16 -0
  463. package/examples/jsm/renderers/common/Renderer.js +895 -0
  464. package/examples/jsm/renderers/common/SampledTexture.js +80 -0
  465. package/examples/jsm/renderers/common/Sampler.js +18 -0
  466. package/examples/jsm/renderers/common/StorageBuffer.js +17 -0
  467. package/examples/jsm/renderers/common/Textures.js +218 -0
  468. package/examples/jsm/renderers/common/Uniform.js +140 -0
  469. package/examples/jsm/renderers/common/UniformBuffer.js +15 -0
  470. package/examples/jsm/renderers/common/UniformsGroup.js +299 -0
  471. package/examples/jsm/renderers/common/nodes/NodeSampledTexture.js +39 -0
  472. package/examples/jsm/renderers/common/nodes/NodeSampler.js +21 -0
  473. package/examples/jsm/renderers/common/nodes/NodeUniform.js +135 -0
  474. package/examples/jsm/renderers/common/nodes/Nodes.js +330 -0
  475. package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +340 -0
  476. package/examples/jsm/renderers/webgl/nodes/SlotNode.js +26 -0
  477. package/examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js +764 -0
  478. package/examples/jsm/renderers/webgl/nodes/WebGLNodes.js +49 -0
  479. package/examples/jsm/renderers/webgpu/WebGPUBackend.js +844 -0
  480. package/examples/jsm/renderers/webgpu/WebGPURenderer.js +32 -0
  481. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +902 -0
  482. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeFunction.js +104 -0
  483. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeParser.js +14 -0
  484. package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +274 -0
  485. package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +223 -0
  486. package/examples/jsm/renderers/webgpu/utils/WebGPUConstants.js +324 -0
  487. package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +533 -0
  488. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureMipmapUtils.js +163 -0
  489. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +964 -0
  490. package/examples/jsm/renderers/webgpu/utils/WebGPUUtils.js +92 -0
  491. package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +87 -0
  492. package/examples/jsm/shaders/AfterimageShader.js +56 -0
  493. package/examples/jsm/shaders/BasicShader.js +27 -0
  494. package/examples/jsm/shaders/BleachBypassShader.js +62 -0
  495. package/examples/jsm/shaders/BlendShader.js +47 -0
  496. package/examples/jsm/shaders/BokehShader.js +143 -0
  497. package/examples/jsm/shaders/BokehShader2.js +393 -0
  498. package/examples/jsm/shaders/BrightnessContrastShader.js +54 -0
  499. package/examples/jsm/shaders/ColorCorrectionShader.js +50 -0
  500. package/examples/jsm/shaders/ColorifyShader.js +51 -0
  501. package/examples/jsm/shaders/ConvolutionShader.js +103 -0
  502. package/examples/jsm/shaders/CopyShader.js +45 -0
  503. package/examples/jsm/shaders/DOFMipMapShader.js +54 -0
  504. package/examples/jsm/shaders/DepthLimitedBlurShader.js +166 -0
  505. package/examples/jsm/shaders/DigitalGlitch.js +101 -0
  506. package/examples/jsm/shaders/DotScreenShader.js +70 -0
  507. package/examples/jsm/shaders/ExposureShader.js +44 -0
  508. package/examples/jsm/shaders/FXAAShader.js +286 -0
  509. package/examples/jsm/shaders/FilmShader.js +102 -0
  510. package/examples/jsm/shaders/FocusShader.js +87 -0
  511. package/examples/jsm/shaders/FreiChenShader.js +94 -0
  512. package/examples/jsm/shaders/GammaCorrectionShader.js +43 -0
  513. package/examples/jsm/shaders/GodRaysShader.js +313 -0
  514. package/examples/jsm/shaders/HalftoneShader.js +310 -0
  515. package/examples/jsm/shaders/HorizontalBlurShader.js +59 -0
  516. package/examples/jsm/shaders/HorizontalTiltShiftShader.js +61 -0
  517. package/examples/jsm/shaders/HueSaturationShader.js +65 -0
  518. package/examples/jsm/shaders/KaleidoShader.js +56 -0
  519. package/examples/jsm/shaders/LuminosityHighPassShader.js +64 -0
  520. package/examples/jsm/shaders/LuminosityShader.js +46 -0
  521. package/examples/jsm/shaders/MMDToonShader.js +132 -0
  522. package/examples/jsm/shaders/MirrorShader.js +54 -0
  523. package/examples/jsm/shaders/NormalMapShader.js +53 -0
  524. package/examples/jsm/shaders/OutputShader.js +78 -0
  525. package/examples/jsm/shaders/RGBShiftShader.js +54 -0
  526. package/examples/jsm/shaders/SAOShader.js +188 -0
  527. package/examples/jsm/shaders/SMAAShader.js +460 -0
  528. package/examples/jsm/shaders/SSAOShader.js +288 -0
  529. package/examples/jsm/shaders/SSRShader.js +364 -0
  530. package/examples/jsm/shaders/SepiaShader.js +52 -0
  531. package/examples/jsm/shaders/SobelOperatorShader.js +90 -0
  532. package/examples/jsm/shaders/SubsurfaceScatteringShader.js +88 -0
  533. package/examples/jsm/shaders/TechnicolorShader.js +43 -0
  534. package/examples/jsm/shaders/ToonShader.js +326 -0
  535. package/examples/jsm/shaders/TriangleBlurShader.js +72 -0
  536. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +45 -0
  537. package/examples/jsm/shaders/VelocityShader.js +128 -0
  538. package/examples/jsm/shaders/VerticalBlurShader.js +59 -0
  539. package/examples/jsm/shaders/VerticalTiltShiftShader.js +61 -0
  540. package/examples/jsm/shaders/VignetteShader.js +51 -0
  541. package/examples/jsm/shaders/VolumeShader.js +289 -0
  542. package/examples/jsm/shaders/WaterRefractionShader.js +93 -0
  543. package/examples/jsm/textures/FlakesTexture.js +40 -0
  544. package/examples/jsm/utils/BufferGeometryUtils.js +1373 -0
  545. package/examples/jsm/utils/CameraUtils.js +73 -0
  546. package/examples/jsm/utils/GPUStatsPanel.js +128 -0
  547. package/examples/jsm/utils/GeometryCompressionUtils.js +639 -0
  548. package/examples/jsm/utils/GeometryUtils.js +221 -0
  549. package/examples/jsm/utils/LDrawUtils.js +202 -0
  550. package/examples/jsm/utils/PackedPhongMaterial.js +178 -0
  551. package/examples/jsm/utils/SceneUtils.js +254 -0
  552. package/examples/jsm/utils/ShadowMapViewer.js +210 -0
  553. package/examples/jsm/utils/SkeletonUtils.js +413 -0
  554. package/examples/jsm/utils/TextureUtils.js +86 -0
  555. package/examples/jsm/utils/UVsDebug.js +165 -0
  556. package/examples/jsm/utils/WorkerPool.js +102 -0
  557. package/examples/jsm/webxr/ARButton.js +208 -0
  558. package/examples/jsm/webxr/OculusHandModel.js +109 -0
  559. package/examples/jsm/webxr/OculusHandPointerModel.js +413 -0
  560. package/examples/jsm/webxr/Text2D.js +38 -0
  561. package/examples/jsm/webxr/VRButton.js +200 -0
  562. package/examples/jsm/webxr/XRButton.js +198 -0
  563. package/examples/jsm/webxr/XRControllerModelFactory.js +299 -0
  564. package/examples/jsm/webxr/XREstimatedLight.js +223 -0
  565. package/examples/jsm/webxr/XRHandMeshModel.js +112 -0
  566. package/examples/jsm/webxr/XRHandModelFactory.js +105 -0
  567. package/examples/jsm/webxr/XRHandPrimitiveModel.js +103 -0
  568. package/examples/jsm/webxr/XRPlanes.js +100 -0
  569. package/lib/3d.min.js +1 -0
  570. package/package.json +25 -12
@@ -0,0 +1,3533 @@
1
+ import {
2
+ BackSide,
3
+ BoxGeometry,
4
+ BufferAttribute,
5
+ BufferGeometry,
6
+ ClampToEdgeWrapping,
7
+ Color,
8
+ ConeGeometry,
9
+ CylinderGeometry,
10
+ DataTexture,
11
+ DoubleSide,
12
+ FileLoader,
13
+ Float32BufferAttribute,
14
+ FrontSide,
15
+ Group,
16
+ LineBasicMaterial,
17
+ LineSegments,
18
+ Loader,
19
+ LoaderUtils,
20
+ Mesh,
21
+ MeshBasicMaterial,
22
+ MeshPhongMaterial,
23
+ Object3D,
24
+ Points,
25
+ PointsMaterial,
26
+ Quaternion,
27
+ RepeatWrapping,
28
+ Scene,
29
+ ShapeUtils,
30
+ SphereGeometry,
31
+ SRGBColorSpace,
32
+ TextureLoader,
33
+ Vector2,
34
+ Vector3
35
+ } from 'three';
36
+ import chevrotain from '../libs/chevrotain.module.min.js';
37
+
38
+
39
+ class VRMLLoader extends Loader {
40
+
41
+ constructor( manager ) {
42
+
43
+ super( manager );
44
+
45
+ }
46
+
47
+ load( url, onLoad, onProgress, onError ) {
48
+
49
+ const scope = this;
50
+
51
+ const path = ( scope.path === '' ) ? LoaderUtils.extractUrlBase( url ) : scope.path;
52
+
53
+ const loader = new FileLoader( scope.manager );
54
+ loader.setPath( scope.path );
55
+ loader.setRequestHeader( scope.requestHeader );
56
+ loader.setWithCredentials( scope.withCredentials );
57
+ loader.load( url, function ( text ) {
58
+
59
+ try {
60
+
61
+ onLoad( scope.parse( text, path ) );
62
+
63
+ } catch ( e ) {
64
+
65
+ if ( onError ) {
66
+
67
+ onError( e );
68
+
69
+ } else {
70
+
71
+ console.error( e );
72
+
73
+ }
74
+
75
+ scope.manager.itemError( url );
76
+
77
+ }
78
+
79
+ }, onProgress, onError );
80
+
81
+ }
82
+
83
+ parse( data, path ) {
84
+
85
+ const nodeMap = {};
86
+
87
+ function generateVRMLTree( data ) {
88
+
89
+ // create lexer, parser and visitor
90
+
91
+ const tokenData = createTokens();
92
+
93
+ const lexer = new VRMLLexer( tokenData.tokens );
94
+ const parser = new VRMLParser( tokenData.tokenVocabulary );
95
+ const visitor = createVisitor( parser.getBaseCstVisitorConstructor() );
96
+
97
+ // lexing
98
+
99
+ const lexingResult = lexer.lex( data );
100
+ parser.input = lexingResult.tokens;
101
+
102
+ // parsing
103
+
104
+ const cstOutput = parser.vrml();
105
+
106
+ if ( parser.errors.length > 0 ) {
107
+
108
+ console.error( parser.errors );
109
+
110
+ throw Error( 'THREE.VRMLLoader: Parsing errors detected.' );
111
+
112
+ }
113
+
114
+ // actions
115
+
116
+ const ast = visitor.visit( cstOutput );
117
+
118
+ return ast;
119
+
120
+ }
121
+
122
+ function createTokens() {
123
+
124
+ const createToken = chevrotain.createToken;
125
+
126
+ // from http://gun.teipir.gr/VRML-amgem/spec/part1/concepts.html#SyntaxBasics
127
+
128
+ const RouteIdentifier = createToken( { name: 'RouteIdentifier', pattern: /[^\x30-\x39\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d][^\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d]*[\.][^\x30-\x39\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d][^\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d]*/ } );
129
+ const Identifier = createToken( { name: 'Identifier', pattern: /[^\x30-\x39\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d][^\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d]*/, longer_alt: RouteIdentifier } );
130
+
131
+ // from http://gun.teipir.gr/VRML-amgem/spec/part1/nodesRef.html
132
+
133
+ const nodeTypes = [
134
+ 'Anchor', 'Billboard', 'Collision', 'Group', 'Transform', // grouping nodes
135
+ 'Inline', 'LOD', 'Switch', // special groups
136
+ 'AudioClip', 'DirectionalLight', 'PointLight', 'Script', 'Shape', 'Sound', 'SpotLight', 'WorldInfo', // common nodes
137
+ 'CylinderSensor', 'PlaneSensor', 'ProximitySensor', 'SphereSensor', 'TimeSensor', 'TouchSensor', 'VisibilitySensor', // sensors
138
+ 'Box', 'Cone', 'Cylinder', 'ElevationGrid', 'Extrusion', 'IndexedFaceSet', 'IndexedLineSet', 'PointSet', 'Sphere', // geometries
139
+ 'Color', 'Coordinate', 'Normal', 'TextureCoordinate', // geometric properties
140
+ 'Appearance', 'FontStyle', 'ImageTexture', 'Material', 'MovieTexture', 'PixelTexture', 'TextureTransform', // appearance
141
+ 'ColorInterpolator', 'CoordinateInterpolator', 'NormalInterpolator', 'OrientationInterpolator', 'PositionInterpolator', 'ScalarInterpolator', // interpolators
142
+ 'Background', 'Fog', 'NavigationInfo', 'Viewpoint', // bindable nodes
143
+ 'Text' // Text must be placed at the end of the regex so there are no matches for TextureTransform and TextureCoordinate
144
+ ];
145
+
146
+ //
147
+
148
+ const Version = createToken( {
149
+ name: 'Version',
150
+ pattern: /#VRML.*/,
151
+ longer_alt: Identifier
152
+ } );
153
+
154
+ const NodeName = createToken( {
155
+ name: 'NodeName',
156
+ pattern: new RegExp( nodeTypes.join( '|' ) ),
157
+ longer_alt: Identifier
158
+ } );
159
+
160
+ const DEF = createToken( {
161
+ name: 'DEF',
162
+ pattern: /DEF/,
163
+ longer_alt: Identifier
164
+ } );
165
+
166
+ const USE = createToken( {
167
+ name: 'USE',
168
+ pattern: /USE/,
169
+ longer_alt: Identifier
170
+ } );
171
+
172
+ const ROUTE = createToken( {
173
+ name: 'ROUTE',
174
+ pattern: /ROUTE/,
175
+ longer_alt: Identifier
176
+ } );
177
+
178
+ const TO = createToken( {
179
+ name: 'TO',
180
+ pattern: /TO/,
181
+ longer_alt: Identifier
182
+ } );
183
+
184
+ //
185
+
186
+ const StringLiteral = createToken( { name: 'StringLiteral', pattern: /"(?:[^\\"\n\r]|\\[bfnrtv"\\/]|\\u[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])*"/ } );
187
+ const HexLiteral = createToken( { name: 'HexLiteral', pattern: /0[xX][0-9a-fA-F]+/ } );
188
+ const NumberLiteral = createToken( { name: 'NumberLiteral', pattern: /[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?/ } );
189
+ const TrueLiteral = createToken( { name: 'TrueLiteral', pattern: /TRUE/ } );
190
+ const FalseLiteral = createToken( { name: 'FalseLiteral', pattern: /FALSE/ } );
191
+ const NullLiteral = createToken( { name: 'NullLiteral', pattern: /NULL/ } );
192
+ const LSquare = createToken( { name: 'LSquare', pattern: /\[/ } );
193
+ const RSquare = createToken( { name: 'RSquare', pattern: /]/ } );
194
+ const LCurly = createToken( { name: 'LCurly', pattern: /{/ } );
195
+ const RCurly = createToken( { name: 'RCurly', pattern: /}/ } );
196
+ const Comment = createToken( {
197
+ name: 'Comment',
198
+ pattern: /#.*/,
199
+ group: chevrotain.Lexer.SKIPPED
200
+ } );
201
+
202
+ // commas, blanks, tabs, newlines and carriage returns are whitespace characters wherever they appear outside of string fields
203
+
204
+ const WhiteSpace = createToken( {
205
+ name: 'WhiteSpace',
206
+ pattern: /[ ,\s]/,
207
+ group: chevrotain.Lexer.SKIPPED
208
+ } );
209
+
210
+ const tokens = [
211
+ WhiteSpace,
212
+ // keywords appear before the Identifier
213
+ NodeName,
214
+ DEF,
215
+ USE,
216
+ ROUTE,
217
+ TO,
218
+ TrueLiteral,
219
+ FalseLiteral,
220
+ NullLiteral,
221
+ // the Identifier must appear after the keywords because all keywords are valid identifiers
222
+ Version,
223
+ Identifier,
224
+ RouteIdentifier,
225
+ StringLiteral,
226
+ HexLiteral,
227
+ NumberLiteral,
228
+ LSquare,
229
+ RSquare,
230
+ LCurly,
231
+ RCurly,
232
+ Comment
233
+ ];
234
+
235
+ const tokenVocabulary = {};
236
+
237
+ for ( let i = 0, l = tokens.length; i < l; i ++ ) {
238
+
239
+ const token = tokens[ i ];
240
+
241
+ tokenVocabulary[ token.name ] = token;
242
+
243
+ }
244
+
245
+ return { tokens: tokens, tokenVocabulary: tokenVocabulary };
246
+
247
+ }
248
+
249
+
250
+ function createVisitor( BaseVRMLVisitor ) {
251
+
252
+ // the visitor is created dynmaically based on the given base class
253
+
254
+ class VRMLToASTVisitor extends BaseVRMLVisitor {
255
+
256
+ constructor() {
257
+
258
+ super();
259
+
260
+ this.validateVisitor();
261
+
262
+ }
263
+
264
+ vrml( ctx ) {
265
+
266
+ const data = {
267
+ version: this.visit( ctx.version ),
268
+ nodes: [],
269
+ routes: []
270
+ };
271
+
272
+ for ( let i = 0, l = ctx.node.length; i < l; i ++ ) {
273
+
274
+ const node = ctx.node[ i ];
275
+
276
+ data.nodes.push( this.visit( node ) );
277
+
278
+ }
279
+
280
+ if ( ctx.route ) {
281
+
282
+ for ( let i = 0, l = ctx.route.length; i < l; i ++ ) {
283
+
284
+ const route = ctx.route[ i ];
285
+
286
+ data.routes.push( this.visit( route ) );
287
+
288
+ }
289
+
290
+ }
291
+
292
+ return data;
293
+
294
+ }
295
+
296
+ version( ctx ) {
297
+
298
+ return ctx.Version[ 0 ].image;
299
+
300
+ }
301
+
302
+ node( ctx ) {
303
+
304
+ const data = {
305
+ name: ctx.NodeName[ 0 ].image,
306
+ fields: []
307
+ };
308
+
309
+ if ( ctx.field ) {
310
+
311
+ for ( let i = 0, l = ctx.field.length; i < l; i ++ ) {
312
+
313
+ const field = ctx.field[ i ];
314
+
315
+ data.fields.push( this.visit( field ) );
316
+
317
+ }
318
+
319
+ }
320
+
321
+ // DEF
322
+
323
+ if ( ctx.def ) {
324
+
325
+ data.DEF = this.visit( ctx.def[ 0 ] );
326
+
327
+ }
328
+
329
+ return data;
330
+
331
+ }
332
+
333
+ field( ctx ) {
334
+
335
+ const data = {
336
+ name: ctx.Identifier[ 0 ].image,
337
+ type: null,
338
+ values: null
339
+ };
340
+
341
+ let result;
342
+
343
+ // SFValue
344
+
345
+ if ( ctx.singleFieldValue ) {
346
+
347
+ result = this.visit( ctx.singleFieldValue[ 0 ] );
348
+
349
+ }
350
+
351
+ // MFValue
352
+
353
+ if ( ctx.multiFieldValue ) {
354
+
355
+ result = this.visit( ctx.multiFieldValue[ 0 ] );
356
+
357
+ }
358
+
359
+ data.type = result.type;
360
+ data.values = result.values;
361
+
362
+ return data;
363
+
364
+ }
365
+
366
+ def( ctx ) {
367
+
368
+ return ( ctx.Identifier || ctx.NodeName )[ 0 ].image;
369
+
370
+ }
371
+
372
+ use( ctx ) {
373
+
374
+ return { USE: ( ctx.Identifier || ctx.NodeName )[ 0 ].image };
375
+
376
+ }
377
+
378
+ singleFieldValue( ctx ) {
379
+
380
+ return processField( this, ctx );
381
+
382
+ }
383
+
384
+ multiFieldValue( ctx ) {
385
+
386
+ return processField( this, ctx );
387
+
388
+ }
389
+
390
+ route( ctx ) {
391
+
392
+ const data = {
393
+ FROM: ctx.RouteIdentifier[ 0 ].image,
394
+ TO: ctx.RouteIdentifier[ 1 ].image
395
+ };
396
+
397
+ return data;
398
+
399
+ }
400
+
401
+ }
402
+
403
+ function processField( scope, ctx ) {
404
+
405
+ const field = {
406
+ type: null,
407
+ values: []
408
+ };
409
+
410
+ if ( ctx.node ) {
411
+
412
+ field.type = 'node';
413
+
414
+ for ( let i = 0, l = ctx.node.length; i < l; i ++ ) {
415
+
416
+ const node = ctx.node[ i ];
417
+
418
+ field.values.push( scope.visit( node ) );
419
+
420
+ }
421
+
422
+ }
423
+
424
+ if ( ctx.use ) {
425
+
426
+ field.type = 'use';
427
+
428
+ for ( let i = 0, l = ctx.use.length; i < l; i ++ ) {
429
+
430
+ const use = ctx.use[ i ];
431
+
432
+ field.values.push( scope.visit( use ) );
433
+
434
+ }
435
+
436
+ }
437
+
438
+ if ( ctx.StringLiteral ) {
439
+
440
+ field.type = 'string';
441
+
442
+ for ( let i = 0, l = ctx.StringLiteral.length; i < l; i ++ ) {
443
+
444
+ const stringLiteral = ctx.StringLiteral[ i ];
445
+
446
+ field.values.push( stringLiteral.image.replace( /'|"/g, '' ) );
447
+
448
+ }
449
+
450
+ }
451
+
452
+ if ( ctx.NumberLiteral ) {
453
+
454
+ field.type = 'number';
455
+
456
+ for ( let i = 0, l = ctx.NumberLiteral.length; i < l; i ++ ) {
457
+
458
+ const numberLiteral = ctx.NumberLiteral[ i ];
459
+
460
+ field.values.push( parseFloat( numberLiteral.image ) );
461
+
462
+ }
463
+
464
+ }
465
+
466
+ if ( ctx.HexLiteral ) {
467
+
468
+ field.type = 'hex';
469
+
470
+ for ( let i = 0, l = ctx.HexLiteral.length; i < l; i ++ ) {
471
+
472
+ const hexLiteral = ctx.HexLiteral[ i ];
473
+
474
+ field.values.push( hexLiteral.image );
475
+
476
+ }
477
+
478
+ }
479
+
480
+ if ( ctx.TrueLiteral ) {
481
+
482
+ field.type = 'boolean';
483
+
484
+ for ( let i = 0, l = ctx.TrueLiteral.length; i < l; i ++ ) {
485
+
486
+ const trueLiteral = ctx.TrueLiteral[ i ];
487
+
488
+ if ( trueLiteral.image === 'TRUE' ) field.values.push( true );
489
+
490
+ }
491
+
492
+ }
493
+
494
+ if ( ctx.FalseLiteral ) {
495
+
496
+ field.type = 'boolean';
497
+
498
+ for ( let i = 0, l = ctx.FalseLiteral.length; i < l; i ++ ) {
499
+
500
+ const falseLiteral = ctx.FalseLiteral[ i ];
501
+
502
+ if ( falseLiteral.image === 'FALSE' ) field.values.push( false );
503
+
504
+ }
505
+
506
+ }
507
+
508
+ if ( ctx.NullLiteral ) {
509
+
510
+ field.type = 'null';
511
+
512
+ ctx.NullLiteral.forEach( function () {
513
+
514
+ field.values.push( null );
515
+
516
+ } );
517
+
518
+ }
519
+
520
+ return field;
521
+
522
+ }
523
+
524
+ return new VRMLToASTVisitor();
525
+
526
+ }
527
+
528
+ function parseTree( tree ) {
529
+
530
+ // console.log( JSON.stringify( tree, null, 2 ) );
531
+
532
+ const nodes = tree.nodes;
533
+ const scene = new Scene();
534
+
535
+ // first iteration: build nodemap based on DEF statements
536
+
537
+ for ( let i = 0, l = nodes.length; i < l; i ++ ) {
538
+
539
+ const node = nodes[ i ];
540
+
541
+ buildNodeMap( node );
542
+
543
+ }
544
+
545
+ // second iteration: build nodes
546
+
547
+ for ( let i = 0, l = nodes.length; i < l; i ++ ) {
548
+
549
+ const node = nodes[ i ];
550
+ const object = getNode( node );
551
+
552
+ if ( object instanceof Object3D ) scene.add( object );
553
+
554
+ if ( node.name === 'WorldInfo' ) scene.userData.worldInfo = object;
555
+
556
+ }
557
+
558
+ return scene;
559
+
560
+ }
561
+
562
+ function buildNodeMap( node ) {
563
+
564
+ if ( node.DEF ) {
565
+
566
+ nodeMap[ node.DEF ] = node;
567
+
568
+ }
569
+
570
+ const fields = node.fields;
571
+
572
+ for ( let i = 0, l = fields.length; i < l; i ++ ) {
573
+
574
+ const field = fields[ i ];
575
+
576
+ if ( field.type === 'node' ) {
577
+
578
+ const fieldValues = field.values;
579
+
580
+ for ( let j = 0, jl = fieldValues.length; j < jl; j ++ ) {
581
+
582
+ buildNodeMap( fieldValues[ j ] );
583
+
584
+ }
585
+
586
+ }
587
+
588
+
589
+ }
590
+
591
+ }
592
+
593
+
594
+ function getNode( node ) {
595
+
596
+ // handle case where a node refers to a different one
597
+
598
+ if ( node.USE ) {
599
+
600
+ return resolveUSE( node.USE );
601
+
602
+ }
603
+
604
+ if ( node.build !== undefined ) return node.build;
605
+
606
+ node.build = buildNode( node );
607
+
608
+ return node.build;
609
+
610
+ }
611
+
612
+ // node builder
613
+
614
+ function buildNode( node ) {
615
+
616
+ const nodeName = node.name;
617
+ let build;
618
+
619
+ switch ( nodeName ) {
620
+
621
+ case 'Anchor':
622
+ case 'Group':
623
+ case 'Transform':
624
+ case 'Collision':
625
+ build = buildGroupingNode( node );
626
+ break;
627
+
628
+ case 'Background':
629
+ build = buildBackgroundNode( node );
630
+ break;
631
+
632
+ case 'Shape':
633
+ build = buildShapeNode( node );
634
+ break;
635
+
636
+ case 'Appearance':
637
+ build = buildAppearanceNode( node );
638
+ break;
639
+
640
+ case 'Material':
641
+ build = buildMaterialNode( node );
642
+ break;
643
+
644
+ case 'ImageTexture':
645
+ build = buildImageTextureNode( node );
646
+ break;
647
+
648
+ case 'PixelTexture':
649
+ build = buildPixelTextureNode( node );
650
+ break;
651
+
652
+ case 'TextureTransform':
653
+ build = buildTextureTransformNode( node );
654
+ break;
655
+
656
+ case 'IndexedFaceSet':
657
+ build = buildIndexedFaceSetNode( node );
658
+ break;
659
+
660
+ case 'IndexedLineSet':
661
+ build = buildIndexedLineSetNode( node );
662
+ break;
663
+
664
+ case 'PointSet':
665
+ build = buildPointSetNode( node );
666
+ break;
667
+
668
+ case 'Box':
669
+ build = buildBoxNode( node );
670
+ break;
671
+
672
+ case 'Cone':
673
+ build = buildConeNode( node );
674
+ break;
675
+
676
+ case 'Cylinder':
677
+ build = buildCylinderNode( node );
678
+ break;
679
+
680
+ case 'Sphere':
681
+ build = buildSphereNode( node );
682
+ break;
683
+
684
+ case 'ElevationGrid':
685
+ build = buildElevationGridNode( node );
686
+ break;
687
+
688
+ case 'Extrusion':
689
+ build = buildExtrusionNode( node );
690
+ break;
691
+
692
+ case 'Color':
693
+ case 'Coordinate':
694
+ case 'Normal':
695
+ case 'TextureCoordinate':
696
+ build = buildGeometricNode( node );
697
+ break;
698
+
699
+ case 'WorldInfo':
700
+ build = buildWorldInfoNode( node );
701
+ break;
702
+
703
+ case 'Billboard':
704
+
705
+ case 'Inline':
706
+ case 'LOD':
707
+ case 'Switch':
708
+
709
+ case 'AudioClip':
710
+ case 'DirectionalLight':
711
+ case 'PointLight':
712
+ case 'Script':
713
+ case 'Sound':
714
+ case 'SpotLight':
715
+
716
+ case 'CylinderSensor':
717
+ case 'PlaneSensor':
718
+ case 'ProximitySensor':
719
+ case 'SphereSensor':
720
+ case 'TimeSensor':
721
+ case 'TouchSensor':
722
+ case 'VisibilitySensor':
723
+
724
+ case 'Text':
725
+
726
+ case 'FontStyle':
727
+ case 'MovieTexture':
728
+
729
+ case 'ColorInterpolator':
730
+ case 'CoordinateInterpolator':
731
+ case 'NormalInterpolator':
732
+ case 'OrientationInterpolator':
733
+ case 'PositionInterpolator':
734
+ case 'ScalarInterpolator':
735
+
736
+ case 'Fog':
737
+ case 'NavigationInfo':
738
+ case 'Viewpoint':
739
+ // node not supported yet
740
+ break;
741
+
742
+ default:
743
+ console.warn( 'THREE.VRMLLoader: Unknown node:', nodeName );
744
+ break;
745
+
746
+ }
747
+
748
+ if ( build !== undefined && node.DEF !== undefined && build.hasOwnProperty( 'name' ) === true ) {
749
+
750
+ build.name = node.DEF;
751
+
752
+ }
753
+
754
+ return build;
755
+
756
+ }
757
+
758
+ function buildGroupingNode( node ) {
759
+
760
+ const object = new Group();
761
+
762
+ //
763
+
764
+ const fields = node.fields;
765
+
766
+ for ( let i = 0, l = fields.length; i < l; i ++ ) {
767
+
768
+ const field = fields[ i ];
769
+ const fieldName = field.name;
770
+ const fieldValues = field.values;
771
+
772
+ switch ( fieldName ) {
773
+
774
+ case 'bboxCenter':
775
+ // field not supported
776
+ break;
777
+
778
+ case 'bboxSize':
779
+ // field not supported
780
+ break;
781
+
782
+ case 'center':
783
+ // field not supported
784
+ break;
785
+
786
+ case 'children':
787
+ parseFieldChildren( fieldValues, object );
788
+ break;
789
+
790
+ case 'description':
791
+ // field not supported
792
+ break;
793
+
794
+ case 'collide':
795
+ // field not supported
796
+ break;
797
+
798
+ case 'parameter':
799
+ // field not supported
800
+ break;
801
+
802
+ case 'rotation':
803
+ const axis = new Vector3( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
804
+ const angle = fieldValues[ 3 ];
805
+ object.quaternion.setFromAxisAngle( axis, angle );
806
+ break;
807
+
808
+ case 'scale':
809
+ object.scale.set( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
810
+ break;
811
+
812
+ case 'scaleOrientation':
813
+ // field not supported
814
+ break;
815
+
816
+ case 'translation':
817
+ object.position.set( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
818
+ break;
819
+
820
+ case 'proxy':
821
+ // field not supported
822
+ break;
823
+
824
+ case 'url':
825
+ // field not supported
826
+ break;
827
+
828
+ default:
829
+ console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
830
+ break;
831
+
832
+ }
833
+
834
+ }
835
+
836
+ return object;
837
+
838
+ }
839
+
840
+ function buildBackgroundNode( node ) {
841
+
842
+ const group = new Group();
843
+
844
+ let groundAngle, groundColor;
845
+ let skyAngle, skyColor;
846
+
847
+ const fields = node.fields;
848
+
849
+ for ( let i = 0, l = fields.length; i < l; i ++ ) {
850
+
851
+ const field = fields[ i ];
852
+ const fieldName = field.name;
853
+ const fieldValues = field.values;
854
+
855
+ switch ( fieldName ) {
856
+
857
+ case 'groundAngle':
858
+ groundAngle = fieldValues;
859
+ break;
860
+
861
+ case 'groundColor':
862
+ groundColor = fieldValues;
863
+ break;
864
+
865
+ case 'backUrl':
866
+ // field not supported
867
+ break;
868
+
869
+ case 'bottomUrl':
870
+ // field not supported
871
+ break;
872
+
873
+ case 'frontUrl':
874
+ // field not supported
875
+ break;
876
+
877
+ case 'leftUrl':
878
+ // field not supported
879
+ break;
880
+
881
+ case 'rightUrl':
882
+ // field not supported
883
+ break;
884
+
885
+ case 'topUrl':
886
+ // field not supported
887
+ break;
888
+
889
+ case 'skyAngle':
890
+ skyAngle = fieldValues;
891
+ break;
892
+
893
+ case 'skyColor':
894
+ skyColor = fieldValues;
895
+ break;
896
+
897
+ default:
898
+ console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
899
+ break;
900
+
901
+ }
902
+
903
+ }
904
+
905
+ const radius = 10000;
906
+
907
+ // sky
908
+
909
+ if ( skyColor ) {
910
+
911
+ const skyGeometry = new SphereGeometry( radius, 32, 16 );
912
+ const skyMaterial = new MeshBasicMaterial( { fog: false, side: BackSide, depthWrite: false, depthTest: false } );
913
+
914
+ if ( skyColor.length > 3 ) {
915
+
916
+ paintFaces( skyGeometry, radius, skyAngle, toColorArray( skyColor ), true );
917
+ skyMaterial.vertexColors = true;
918
+
919
+ } else {
920
+
921
+ skyMaterial.color.setRGB( skyColor[ 0 ], skyColor[ 1 ], skyColor[ 2 ] );
922
+ skyMaterial.color.convertSRGBToLinear();
923
+
924
+ }
925
+
926
+ const sky = new Mesh( skyGeometry, skyMaterial );
927
+ group.add( sky );
928
+
929
+ }
930
+
931
+ // ground
932
+
933
+ if ( groundColor ) {
934
+
935
+ if ( groundColor.length > 0 ) {
936
+
937
+ const groundGeometry = new SphereGeometry( radius, 32, 16, 0, 2 * Math.PI, 0.5 * Math.PI, 1.5 * Math.PI );
938
+ const groundMaterial = new MeshBasicMaterial( { fog: false, side: BackSide, vertexColors: true, depthWrite: false, depthTest: false } );
939
+
940
+ paintFaces( groundGeometry, radius, groundAngle, toColorArray( groundColor ), false );
941
+
942
+ const ground = new Mesh( groundGeometry, groundMaterial );
943
+ group.add( ground );
944
+
945
+ }
946
+
947
+ }
948
+
949
+ // render background group first
950
+
951
+ group.renderOrder = - Infinity;
952
+
953
+ return group;
954
+
955
+ }
956
+
957
+ function buildShapeNode( node ) {
958
+
959
+ const fields = node.fields;
960
+
961
+ // if the appearance field is NULL or unspecified, lighting is off and the unlit object color is (0, 0, 0)
962
+
963
+ let material = new MeshBasicMaterial( {
964
+ name: Loader.DEFAULT_MATERIAL_NAME,
965
+ color: 0x000000
966
+ } );
967
+ let geometry;
968
+
969
+ for ( let i = 0, l = fields.length; i < l; i ++ ) {
970
+
971
+ const field = fields[ i ];
972
+ const fieldName = field.name;
973
+ const fieldValues = field.values;
974
+
975
+ switch ( fieldName ) {
976
+
977
+ case 'appearance':
978
+ if ( fieldValues[ 0 ] !== null ) {
979
+
980
+ material = getNode( fieldValues[ 0 ] );
981
+
982
+ }
983
+
984
+ break;
985
+
986
+ case 'geometry':
987
+ if ( fieldValues[ 0 ] !== null ) {
988
+
989
+ geometry = getNode( fieldValues[ 0 ] );
990
+
991
+ }
992
+
993
+ break;
994
+
995
+ default:
996
+ console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
997
+ break;
998
+
999
+ }
1000
+
1001
+ }
1002
+
1003
+ // build 3D object
1004
+
1005
+ let object;
1006
+
1007
+ if ( geometry && geometry.attributes.position ) {
1008
+
1009
+ const type = geometry._type;
1010
+
1011
+ if ( type === 'points' ) { // points
1012
+
1013
+ const pointsMaterial = new PointsMaterial( {
1014
+ name: Loader.DEFAULT_MATERIAL_NAME,
1015
+ color: 0xffffff
1016
+ } );
1017
+
1018
+ if ( geometry.attributes.color !== undefined ) {
1019
+
1020
+ pointsMaterial.vertexColors = true;
1021
+
1022
+ } else {
1023
+
1024
+ // 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
1025
+
1026
+ if ( material.isMeshPhongMaterial ) {
1027
+
1028
+ pointsMaterial.color.copy( material.emissive );
1029
+
1030
+ }
1031
+
1032
+ }
1033
+
1034
+ object = new Points( geometry, pointsMaterial );
1035
+
1036
+ } else if ( type === 'line' ) { // lines
1037
+
1038
+ const lineMaterial = new LineBasicMaterial( {
1039
+ name: Loader.DEFAULT_MATERIAL_NAME,
1040
+ color: 0xffffff
1041
+ } );
1042
+
1043
+ if ( geometry.attributes.color !== undefined ) {
1044
+
1045
+ lineMaterial.vertexColors = true;
1046
+
1047
+ } else {
1048
+
1049
+ // 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
1050
+
1051
+ if ( material.isMeshPhongMaterial ) {
1052
+
1053
+ lineMaterial.color.copy( material.emissive );
1054
+
1055
+ }
1056
+
1057
+ }
1058
+
1059
+ object = new LineSegments( geometry, lineMaterial );
1060
+
1061
+ } else { // consider meshes
1062
+
1063
+ // check "solid" hint (it's placed in the geometry but affects the material)
1064
+
1065
+ if ( geometry._solid !== undefined ) {
1066
+
1067
+ material.side = ( geometry._solid ) ? FrontSide : DoubleSide;
1068
+
1069
+ }
1070
+
1071
+ // check for vertex colors
1072
+
1073
+ if ( geometry.attributes.color !== undefined ) {
1074
+
1075
+ material.vertexColors = true;
1076
+
1077
+ }
1078
+
1079
+ object = new Mesh( geometry, material );
1080
+
1081
+ }
1082
+
1083
+ } else {
1084
+
1085
+ object = new Object3D();
1086
+
1087
+ // if the geometry field is NULL or no vertices are defined the object is not drawn
1088
+
1089
+ object.visible = false;
1090
+
1091
+ }
1092
+
1093
+ return object;
1094
+
1095
+ }
1096
+
1097
+ function buildAppearanceNode( node ) {
1098
+
1099
+ let material = new MeshPhongMaterial();
1100
+ let transformData;
1101
+
1102
+ const fields = node.fields;
1103
+
1104
+ for ( let i = 0, l = fields.length; i < l; i ++ ) {
1105
+
1106
+ const field = fields[ i ];
1107
+ const fieldName = field.name;
1108
+ const fieldValues = field.values;
1109
+
1110
+ switch ( fieldName ) {
1111
+
1112
+ case 'material':
1113
+ if ( fieldValues[ 0 ] !== null ) {
1114
+
1115
+ const materialData = getNode( fieldValues[ 0 ] );
1116
+
1117
+ if ( materialData.diffuseColor ) material.color.copy( materialData.diffuseColor );
1118
+ if ( materialData.emissiveColor ) material.emissive.copy( materialData.emissiveColor );
1119
+ if ( materialData.shininess ) material.shininess = materialData.shininess;
1120
+ if ( materialData.specularColor ) material.specular.copy( materialData.specularColor );
1121
+ if ( materialData.transparency ) material.opacity = 1 - materialData.transparency;
1122
+ if ( materialData.transparency > 0 ) material.transparent = true;
1123
+
1124
+ } else {
1125
+
1126
+ // if the material field is NULL or unspecified, lighting is off and the unlit object color is (0, 0, 0)
1127
+
1128
+ material = new MeshBasicMaterial( {
1129
+ name: Loader.DEFAULT_MATERIAL_NAME,
1130
+ color: 0x000000
1131
+ } );
1132
+
1133
+ }
1134
+
1135
+ break;
1136
+
1137
+ case 'texture':
1138
+ const textureNode = fieldValues[ 0 ];
1139
+ if ( textureNode !== null ) {
1140
+
1141
+ if ( textureNode.name === 'ImageTexture' || textureNode.name === 'PixelTexture' ) {
1142
+
1143
+ material.map = getNode( textureNode );
1144
+
1145
+ } else {
1146
+
1147
+ // MovieTexture not supported yet
1148
+
1149
+ }
1150
+
1151
+ }
1152
+
1153
+ break;
1154
+
1155
+ case 'textureTransform':
1156
+ if ( fieldValues[ 0 ] !== null ) {
1157
+
1158
+ transformData = getNode( fieldValues[ 0 ] );
1159
+
1160
+ }
1161
+
1162
+ break;
1163
+
1164
+ default:
1165
+ console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
1166
+ break;
1167
+
1168
+ }
1169
+
1170
+ }
1171
+
1172
+ // only apply texture transform data if a texture was defined
1173
+
1174
+ if ( material.map ) {
1175
+
1176
+ // respect VRML lighting model
1177
+
1178
+ if ( material.map.__type ) {
1179
+
1180
+ switch ( material.map.__type ) {
1181
+
1182
+ case TEXTURE_TYPE.INTENSITY_ALPHA:
1183
+ material.opacity = 1; // ignore transparency
1184
+ break;
1185
+
1186
+ case TEXTURE_TYPE.RGB:
1187
+ material.color.set( 0xffffff ); // ignore material color
1188
+ break;
1189
+
1190
+ case TEXTURE_TYPE.RGBA:
1191
+ material.color.set( 0xffffff ); // ignore material color
1192
+ material.opacity = 1; // ignore transparency
1193
+ break;
1194
+
1195
+ default:
1196
+
1197
+ }
1198
+
1199
+ delete material.map.__type;
1200
+
1201
+ }
1202
+
1203
+ // apply texture transform
1204
+
1205
+ if ( transformData ) {
1206
+
1207
+ material.map.center.copy( transformData.center );
1208
+ material.map.rotation = transformData.rotation;
1209
+ material.map.repeat.copy( transformData.scale );
1210
+ material.map.offset.copy( transformData.translation );
1211
+
1212
+ }
1213
+
1214
+ }
1215
+
1216
+ return material;
1217
+
1218
+ }
1219
+
1220
+ function buildMaterialNode( node ) {
1221
+
1222
+ const materialData = {};
1223
+
1224
+ const fields = node.fields;
1225
+
1226
+ for ( let i = 0, l = fields.length; i < l; i ++ ) {
1227
+
1228
+ const field = fields[ i ];
1229
+ const fieldName = field.name;
1230
+ const fieldValues = field.values;
1231
+
1232
+ switch ( fieldName ) {
1233
+
1234
+ case 'ambientIntensity':
1235
+ // field not supported
1236
+ break;
1237
+
1238
+ case 'diffuseColor':
1239
+ materialData.diffuseColor = new Color( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
1240
+ materialData.diffuseColor.convertSRGBToLinear();
1241
+ break;
1242
+
1243
+ case 'emissiveColor':
1244
+ materialData.emissiveColor = new Color( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
1245
+ materialData.emissiveColor.convertSRGBToLinear();
1246
+ break;
1247
+
1248
+ case 'shininess':
1249
+ materialData.shininess = fieldValues[ 0 ];
1250
+ break;
1251
+
1252
+ case 'specularColor':
1253
+ materialData.specularColor = new Color( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
1254
+ materialData.specularColor.convertSRGBToLinear();
1255
+ break;
1256
+
1257
+ case 'transparency':
1258
+ materialData.transparency = fieldValues[ 0 ];
1259
+ break;
1260
+
1261
+ default:
1262
+ console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
1263
+ break;
1264
+
1265
+ }
1266
+
1267
+ }
1268
+
1269
+ return materialData;
1270
+
1271
+ }
1272
+
1273
+ function parseHexColor( hex, textureType, color ) {
1274
+
1275
+ let value;
1276
+
1277
+ switch ( textureType ) {
1278
+
1279
+ case TEXTURE_TYPE.INTENSITY:
1280
+ // Intensity texture: A one-component image specifies one-byte hexadecimal or integer values representing the intensity of the image
1281
+ value = parseInt( hex );
1282
+ color.r = value;
1283
+ color.g = value;
1284
+ color.b = value;
1285
+ color.a = 1;
1286
+ break;
1287
+
1288
+ case TEXTURE_TYPE.INTENSITY_ALPHA:
1289
+ // Intensity+Alpha texture: A two-component image specifies the intensity in the first (high) byte and the alpha opacity in the second (low) byte.
1290
+ value = parseInt( '0x' + hex.substring( 2, 4 ) );
1291
+ color.r = value;
1292
+ color.g = value;
1293
+ color.b = value;
1294
+ color.a = parseInt( '0x' + hex.substring( 4, 6 ) );
1295
+ break;
1296
+
1297
+ case TEXTURE_TYPE.RGB:
1298
+ // RGB texture: Pixels in a three-component image specify the red component in the first (high) byte, followed by the green and blue components
1299
+ color.r = parseInt( '0x' + hex.substring( 2, 4 ) );
1300
+ color.g = parseInt( '0x' + hex.substring( 4, 6 ) );
1301
+ color.b = parseInt( '0x' + hex.substring( 6, 8 ) );
1302
+ color.a = 1;
1303
+ break;
1304
+
1305
+ case TEXTURE_TYPE.RGBA:
1306
+ // RGBA texture: Four-component images specify the alpha opacity byte after red/green/blue
1307
+ color.r = parseInt( '0x' + hex.substring( 2, 4 ) );
1308
+ color.g = parseInt( '0x' + hex.substring( 4, 6 ) );
1309
+ color.b = parseInt( '0x' + hex.substring( 6, 8 ) );
1310
+ color.a = parseInt( '0x' + hex.substring( 8, 10 ) );
1311
+ break;
1312
+
1313
+ default:
1314
+
1315
+ }
1316
+
1317
+ }
1318
+
1319
+ function getTextureType( num_components ) {
1320
+
1321
+ let type;
1322
+
1323
+ switch ( num_components ) {
1324
+
1325
+ case 1:
1326
+ type = TEXTURE_TYPE.INTENSITY;
1327
+ break;
1328
+
1329
+ case 2:
1330
+ type = TEXTURE_TYPE.INTENSITY_ALPHA;
1331
+ break;
1332
+
1333
+ case 3:
1334
+ type = TEXTURE_TYPE.RGB;
1335
+ break;
1336
+
1337
+ case 4:
1338
+ type = TEXTURE_TYPE.RGBA;
1339
+ break;
1340
+
1341
+ default:
1342
+
1343
+ }
1344
+
1345
+ return type;
1346
+
1347
+ }
1348
+
1349
+ function buildPixelTextureNode( node ) {
1350
+
1351
+ let texture;
1352
+ let wrapS = RepeatWrapping;
1353
+ let wrapT = RepeatWrapping;
1354
+
1355
+ const fields = node.fields;
1356
+
1357
+ for ( let i = 0, l = fields.length; i < l; i ++ ) {
1358
+
1359
+ const field = fields[ i ];
1360
+ const fieldName = field.name;
1361
+ const fieldValues = field.values;
1362
+
1363
+ switch ( fieldName ) {
1364
+
1365
+ case 'image':
1366
+ const width = fieldValues[ 0 ];
1367
+ const height = fieldValues[ 1 ];
1368
+ const num_components = fieldValues[ 2 ];
1369
+
1370
+ const textureType = getTextureType( num_components );
1371
+
1372
+ const data = new Uint8Array( 4 * width * height );
1373
+
1374
+ const color = { r: 0, g: 0, b: 0, a: 0 };
1375
+
1376
+ for ( let j = 3, k = 0, jl = fieldValues.length; j < jl; j ++, k ++ ) {
1377
+
1378
+ parseHexColor( fieldValues[ j ], textureType, color );
1379
+
1380
+ const stride = k * 4;
1381
+
1382
+ data[ stride + 0 ] = color.r;
1383
+ data[ stride + 1 ] = color.g;
1384
+ data[ stride + 2 ] = color.b;
1385
+ data[ stride + 3 ] = color.a;
1386
+
1387
+ }
1388
+
1389
+ texture = new DataTexture( data, width, height );
1390
+ texture.colorSpace = SRGBColorSpace;
1391
+ texture.needsUpdate = true;
1392
+ texture.__type = textureType; // needed for material modifications
1393
+ break;
1394
+
1395
+ case 'repeatS':
1396
+ if ( fieldValues[ 0 ] === false ) wrapS = ClampToEdgeWrapping;
1397
+ break;
1398
+
1399
+ case 'repeatT':
1400
+ if ( fieldValues[ 0 ] === false ) wrapT = ClampToEdgeWrapping;
1401
+ break;
1402
+
1403
+ default:
1404
+ console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
1405
+ break;
1406
+
1407
+ }
1408
+
1409
+ }
1410
+
1411
+ if ( texture ) {
1412
+
1413
+ texture.wrapS = wrapS;
1414
+ texture.wrapT = wrapT;
1415
+
1416
+ }
1417
+
1418
+ return texture;
1419
+
1420
+ }
1421
+
1422
+ function buildImageTextureNode( node ) {
1423
+
1424
+ let texture;
1425
+ let wrapS = RepeatWrapping;
1426
+ let wrapT = RepeatWrapping;
1427
+
1428
+ const fields = node.fields;
1429
+
1430
+ for ( let i = 0, l = fields.length; i < l; i ++ ) {
1431
+
1432
+ const field = fields[ i ];
1433
+ const fieldName = field.name;
1434
+ const fieldValues = field.values;
1435
+
1436
+ switch ( fieldName ) {
1437
+
1438
+ case 'url':
1439
+ const url = fieldValues[ 0 ];
1440
+ if ( url ) texture = textureLoader.load( url );
1441
+ break;
1442
+
1443
+ case 'repeatS':
1444
+ if ( fieldValues[ 0 ] === false ) wrapS = ClampToEdgeWrapping;
1445
+ break;
1446
+
1447
+ case 'repeatT':
1448
+ if ( fieldValues[ 0 ] === false ) wrapT = ClampToEdgeWrapping;
1449
+ break;
1450
+
1451
+ default:
1452
+ console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
1453
+ break;
1454
+
1455
+ }
1456
+
1457
+ }
1458
+
1459
+ if ( texture ) {
1460
+
1461
+ texture.wrapS = wrapS;
1462
+ texture.wrapT = wrapT;
1463
+ texture.colorSpace = SRGBColorSpace;
1464
+
1465
+ }
1466
+
1467
+ return texture;
1468
+
1469
+ }
1470
+
1471
+ function buildTextureTransformNode( node ) {
1472
+
1473
+ const transformData = {
1474
+ center: new Vector2(),
1475
+ rotation: new Vector2(),
1476
+ scale: new Vector2(),
1477
+ translation: new Vector2()
1478
+ };
1479
+
1480
+ const fields = node.fields;
1481
+
1482
+ for ( let i = 0, l = fields.length; i < l; i ++ ) {
1483
+
1484
+ const field = fields[ i ];
1485
+ const fieldName = field.name;
1486
+ const fieldValues = field.values;
1487
+
1488
+ switch ( fieldName ) {
1489
+
1490
+ case 'center':
1491
+ transformData.center.set( fieldValues[ 0 ], fieldValues[ 1 ] );
1492
+ break;
1493
+
1494
+ case 'rotation':
1495
+ transformData.rotation = fieldValues[ 0 ];
1496
+ break;
1497
+
1498
+ case 'scale':
1499
+ transformData.scale.set( fieldValues[ 0 ], fieldValues[ 1 ] );
1500
+ break;
1501
+
1502
+ case 'translation':
1503
+ transformData.translation.set( fieldValues[ 0 ], fieldValues[ 1 ] );
1504
+ break;
1505
+
1506
+ default:
1507
+ console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
1508
+ break;
1509
+
1510
+ }
1511
+
1512
+ }
1513
+
1514
+ return transformData;
1515
+
1516
+ }
1517
+
1518
+ function buildGeometricNode( node ) {
1519
+
1520
+ return node.fields[ 0 ].values;
1521
+
1522
+ }
1523
+
1524
+ function buildWorldInfoNode( node ) {
1525
+
1526
+ const worldInfo = {};
1527
+
1528
+ const fields = node.fields;
1529
+
1530
+ for ( let i = 0, l = fields.length; i < l; i ++ ) {
1531
+
1532
+ const field = fields[ i ];
1533
+ const fieldName = field.name;
1534
+ const fieldValues = field.values;
1535
+
1536
+ switch ( fieldName ) {
1537
+
1538
+ case 'title':
1539
+ worldInfo.title = fieldValues[ 0 ];
1540
+ break;
1541
+
1542
+ case 'info':
1543
+ worldInfo.info = fieldValues;
1544
+ break;
1545
+
1546
+ default:
1547
+ console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
1548
+ break;
1549
+
1550
+ }
1551
+
1552
+ }
1553
+
1554
+ return worldInfo;
1555
+
1556
+ }
1557
+
1558
+ function buildIndexedFaceSetNode( node ) {
1559
+
1560
+ let color, coord, normal, texCoord;
1561
+ let ccw = true, solid = true, creaseAngle = 0;
1562
+ let colorIndex, coordIndex, normalIndex, texCoordIndex;
1563
+ let colorPerVertex = true, normalPerVertex = true;
1564
+
1565
+ const fields = node.fields;
1566
+
1567
+ for ( let i = 0, l = fields.length; i < l; i ++ ) {
1568
+
1569
+ const field = fields[ i ];
1570
+ const fieldName = field.name;
1571
+ const fieldValues = field.values;
1572
+
1573
+ switch ( fieldName ) {
1574
+
1575
+ case 'color':
1576
+ const colorNode = fieldValues[ 0 ];
1577
+
1578
+ if ( colorNode !== null ) {
1579
+
1580
+ color = getNode( colorNode );
1581
+
1582
+ }
1583
+
1584
+ break;
1585
+
1586
+ case 'coord':
1587
+ const coordNode = fieldValues[ 0 ];
1588
+
1589
+ if ( coordNode !== null ) {
1590
+
1591
+ coord = getNode( coordNode );
1592
+
1593
+ }
1594
+
1595
+ break;
1596
+
1597
+ case 'normal':
1598
+ const normalNode = fieldValues[ 0 ];
1599
+
1600
+ if ( normalNode !== null ) {
1601
+
1602
+ normal = getNode( normalNode );
1603
+
1604
+ }
1605
+
1606
+ break;
1607
+
1608
+ case 'texCoord':
1609
+ const texCoordNode = fieldValues[ 0 ];
1610
+
1611
+ if ( texCoordNode !== null ) {
1612
+
1613
+ texCoord = getNode( texCoordNode );
1614
+
1615
+ }
1616
+
1617
+ break;
1618
+
1619
+ case 'ccw':
1620
+ ccw = fieldValues[ 0 ];
1621
+ break;
1622
+
1623
+ case 'colorIndex':
1624
+ colorIndex = fieldValues;
1625
+ break;
1626
+
1627
+ case 'colorPerVertex':
1628
+ colorPerVertex = fieldValues[ 0 ];
1629
+ break;
1630
+
1631
+ case 'convex':
1632
+ // field not supported
1633
+ break;
1634
+
1635
+ case 'coordIndex':
1636
+ coordIndex = fieldValues;
1637
+ break;
1638
+
1639
+ case 'creaseAngle':
1640
+ creaseAngle = fieldValues[ 0 ];
1641
+ break;
1642
+
1643
+ case 'normalIndex':
1644
+ normalIndex = fieldValues;
1645
+ break;
1646
+
1647
+ case 'normalPerVertex':
1648
+ normalPerVertex = fieldValues[ 0 ];
1649
+ break;
1650
+
1651
+ case 'solid':
1652
+ solid = fieldValues[ 0 ];
1653
+ break;
1654
+
1655
+ case 'texCoordIndex':
1656
+ texCoordIndex = fieldValues;
1657
+ break;
1658
+
1659
+ default:
1660
+ console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
1661
+ break;
1662
+
1663
+ }
1664
+
1665
+ }
1666
+
1667
+ if ( coordIndex === undefined ) {
1668
+
1669
+ console.warn( 'THREE.VRMLLoader: Missing coordIndex.' );
1670
+
1671
+ return new BufferGeometry(); // handle VRML files with incomplete geometry definition
1672
+
1673
+ }
1674
+
1675
+ const triangulatedCoordIndex = triangulateFaceIndex( coordIndex, ccw );
1676
+
1677
+ let colorAttribute;
1678
+ let normalAttribute;
1679
+ let uvAttribute;
1680
+
1681
+ if ( color ) {
1682
+
1683
+ if ( colorPerVertex === true ) {
1684
+
1685
+ if ( colorIndex && colorIndex.length > 0 ) {
1686
+
1687
+ // if the colorIndex field is not empty, then it is used to choose colors for each vertex of the IndexedFaceSet.
1688
+
1689
+ const triangulatedColorIndex = triangulateFaceIndex( colorIndex, ccw );
1690
+ colorAttribute = computeAttributeFromIndexedData( triangulatedCoordIndex, triangulatedColorIndex, color, 3 );
1691
+
1692
+ } else {
1693
+
1694
+ // if the colorIndex field is empty, then the coordIndex field is used to choose colors from the Color node
1695
+
1696
+ colorAttribute = toNonIndexedAttribute( triangulatedCoordIndex, new Float32BufferAttribute( color, 3 ) );
1697
+
1698
+ }
1699
+
1700
+ } else {
1701
+
1702
+ if ( colorIndex && colorIndex.length > 0 ) {
1703
+
1704
+ // if the colorIndex field is not empty, then they are used to choose one color for each face of the IndexedFaceSet
1705
+
1706
+ const flattenFaceColors = flattenData( color, colorIndex );
1707
+ const triangulatedFaceColors = triangulateFaceData( flattenFaceColors, coordIndex );
1708
+ colorAttribute = computeAttributeFromFaceData( triangulatedCoordIndex, triangulatedFaceColors );
1709
+
1710
+ } else {
1711
+
1712
+ // if the colorIndex field is empty, then the color are applied to each face of the IndexedFaceSet in order
1713
+
1714
+ const triangulatedFaceColors = triangulateFaceData( color, coordIndex );
1715
+ colorAttribute = computeAttributeFromFaceData( triangulatedCoordIndex, triangulatedFaceColors );
1716
+
1717
+
1718
+ }
1719
+
1720
+ }
1721
+
1722
+ convertColorsToLinearSRGB( colorAttribute );
1723
+
1724
+ }
1725
+
1726
+ if ( normal ) {
1727
+
1728
+ if ( normalPerVertex === true ) {
1729
+
1730
+ // consider vertex normals
1731
+
1732
+ if ( normalIndex && normalIndex.length > 0 ) {
1733
+
1734
+ // if the normalIndex field is not empty, then it is used to choose normals for each vertex of the IndexedFaceSet.
1735
+
1736
+ const triangulatedNormalIndex = triangulateFaceIndex( normalIndex, ccw );
1737
+ normalAttribute = computeAttributeFromIndexedData( triangulatedCoordIndex, triangulatedNormalIndex, normal, 3 );
1738
+
1739
+ } else {
1740
+
1741
+ // if the normalIndex field is empty, then the coordIndex field is used to choose normals from the Normal node
1742
+
1743
+ normalAttribute = toNonIndexedAttribute( triangulatedCoordIndex, new Float32BufferAttribute( normal, 3 ) );
1744
+
1745
+ }
1746
+
1747
+ } else {
1748
+
1749
+ // consider face normals
1750
+
1751
+ if ( normalIndex && normalIndex.length > 0 ) {
1752
+
1753
+ // if the normalIndex field is not empty, then they are used to choose one normal for each face of the IndexedFaceSet
1754
+
1755
+ const flattenFaceNormals = flattenData( normal, normalIndex );
1756
+ const triangulatedFaceNormals = triangulateFaceData( flattenFaceNormals, coordIndex );
1757
+ normalAttribute = computeAttributeFromFaceData( triangulatedCoordIndex, triangulatedFaceNormals );
1758
+
1759
+ } else {
1760
+
1761
+ // if the normalIndex field is empty, then the normals are applied to each face of the IndexedFaceSet in order
1762
+
1763
+ const triangulatedFaceNormals = triangulateFaceData( normal, coordIndex );
1764
+ normalAttribute = computeAttributeFromFaceData( triangulatedCoordIndex, triangulatedFaceNormals );
1765
+
1766
+ }
1767
+
1768
+ }
1769
+
1770
+ } else {
1771
+
1772
+ // 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
1773
+
1774
+ normalAttribute = computeNormalAttribute( triangulatedCoordIndex, coord, creaseAngle );
1775
+
1776
+ }
1777
+
1778
+ if ( texCoord ) {
1779
+
1780
+ // texture coordinates are always defined on vertex level
1781
+
1782
+ if ( texCoordIndex && texCoordIndex.length > 0 ) {
1783
+
1784
+ // if the texCoordIndex field is not empty, then it is used to choose texture coordinates for each vertex of the IndexedFaceSet.
1785
+
1786
+ const triangulatedTexCoordIndex = triangulateFaceIndex( texCoordIndex, ccw );
1787
+ uvAttribute = computeAttributeFromIndexedData( triangulatedCoordIndex, triangulatedTexCoordIndex, texCoord, 2 );
1788
+
1789
+
1790
+ } else {
1791
+
1792
+ // if the texCoordIndex field is empty, then the coordIndex array is used to choose texture coordinates from the TextureCoordinate node
1793
+
1794
+ uvAttribute = toNonIndexedAttribute( triangulatedCoordIndex, new Float32BufferAttribute( texCoord, 2 ) );
1795
+
1796
+ }
1797
+
1798
+ }
1799
+
1800
+ const geometry = new BufferGeometry();
1801
+ const positionAttribute = toNonIndexedAttribute( triangulatedCoordIndex, new Float32BufferAttribute( coord, 3 ) );
1802
+
1803
+ geometry.setAttribute( 'position', positionAttribute );
1804
+ geometry.setAttribute( 'normal', normalAttribute );
1805
+
1806
+ // optional attributes
1807
+
1808
+ if ( colorAttribute ) geometry.setAttribute( 'color', colorAttribute );
1809
+ if ( uvAttribute ) geometry.setAttribute( 'uv', uvAttribute );
1810
+
1811
+ // "solid" influences the material so let's store it for later use
1812
+
1813
+ geometry._solid = solid;
1814
+ geometry._type = 'mesh';
1815
+
1816
+ return geometry;
1817
+
1818
+ }
1819
+
1820
+ function buildIndexedLineSetNode( node ) {
1821
+
1822
+ let color, coord;
1823
+ let colorIndex, coordIndex;
1824
+ let colorPerVertex = true;
1825
+
1826
+ const fields = node.fields;
1827
+
1828
+ for ( let i = 0, l = fields.length; i < l; i ++ ) {
1829
+
1830
+ const field = fields[ i ];
1831
+ const fieldName = field.name;
1832
+ const fieldValues = field.values;
1833
+
1834
+ switch ( fieldName ) {
1835
+
1836
+ case 'color':
1837
+ const colorNode = fieldValues[ 0 ];
1838
+
1839
+ if ( colorNode !== null ) {
1840
+
1841
+ color = getNode( colorNode );
1842
+
1843
+ }
1844
+
1845
+ break;
1846
+
1847
+ case 'coord':
1848
+ const coordNode = fieldValues[ 0 ];
1849
+
1850
+ if ( coordNode !== null ) {
1851
+
1852
+ coord = getNode( coordNode );
1853
+
1854
+ }
1855
+
1856
+ break;
1857
+
1858
+ case 'colorIndex':
1859
+ colorIndex = fieldValues;
1860
+ break;
1861
+
1862
+ case 'colorPerVertex':
1863
+ colorPerVertex = fieldValues[ 0 ];
1864
+ break;
1865
+
1866
+ case 'coordIndex':
1867
+ coordIndex = fieldValues;
1868
+ break;
1869
+
1870
+ default:
1871
+ console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
1872
+ break;
1873
+
1874
+ }
1875
+
1876
+ }
1877
+
1878
+ // build lines
1879
+
1880
+ let colorAttribute;
1881
+
1882
+ const expandedLineIndex = expandLineIndex( coordIndex ); // create an index for three.js's linesegment primitive
1883
+
1884
+ if ( color ) {
1885
+
1886
+ if ( colorPerVertex === true ) {
1887
+
1888
+ if ( colorIndex.length > 0 ) {
1889
+
1890
+ // if the colorIndex field is not empty, then one color is used for each polyline of the IndexedLineSet.
1891
+
1892
+ const expandedColorIndex = expandLineIndex( colorIndex ); // compute colors for each line segment (rendering primitve)
1893
+ colorAttribute = computeAttributeFromIndexedData( expandedLineIndex, expandedColorIndex, color, 3 ); // compute data on vertex level
1894
+
1895
+ } else {
1896
+
1897
+ // if the colorIndex field is empty, then the colors are applied to each polyline of the IndexedLineSet in order.
1898
+
1899
+ colorAttribute = toNonIndexedAttribute( expandedLineIndex, new Float32BufferAttribute( color, 3 ) );
1900
+
1901
+ }
1902
+
1903
+ } else {
1904
+
1905
+ if ( colorIndex.length > 0 ) {
1906
+
1907
+ // if the colorIndex field is not empty, then colors are applied to each vertex of the IndexedLineSet
1908
+
1909
+ const flattenLineColors = flattenData( color, colorIndex ); // compute colors for each VRML primitve
1910
+ const expandedLineColors = expandLineData( flattenLineColors, coordIndex ); // compute colors for each line segment (rendering primitve)
1911
+ colorAttribute = computeAttributeFromLineData( expandedLineIndex, expandedLineColors ); // compute data on vertex level
1912
+
1913
+
1914
+ } else {
1915
+
1916
+ // if the colorIndex field is empty, then the coordIndex field is used to choose colors from the Color node
1917
+
1918
+ const expandedLineColors = expandLineData( color, coordIndex ); // compute colors for each line segment (rendering primitve)
1919
+ colorAttribute = computeAttributeFromLineData( expandedLineIndex, expandedLineColors ); // compute data on vertex level
1920
+
1921
+ }
1922
+
1923
+ }
1924
+
1925
+ convertColorsToLinearSRGB( colorAttribute );
1926
+
1927
+ }
1928
+
1929
+ //
1930
+
1931
+ const geometry = new BufferGeometry();
1932
+
1933
+ const positionAttribute = toNonIndexedAttribute( expandedLineIndex, new Float32BufferAttribute( coord, 3 ) );
1934
+ geometry.setAttribute( 'position', positionAttribute );
1935
+
1936
+ if ( colorAttribute ) geometry.setAttribute( 'color', colorAttribute );
1937
+
1938
+ geometry._type = 'line';
1939
+
1940
+ return geometry;
1941
+
1942
+ }
1943
+
1944
+ function buildPointSetNode( node ) {
1945
+
1946
+ let color, coord;
1947
+
1948
+ const fields = node.fields;
1949
+
1950
+ for ( let i = 0, l = fields.length; i < l; i ++ ) {
1951
+
1952
+ const field = fields[ i ];
1953
+ const fieldName = field.name;
1954
+ const fieldValues = field.values;
1955
+
1956
+ switch ( fieldName ) {
1957
+
1958
+ case 'color':
1959
+ const colorNode = fieldValues[ 0 ];
1960
+
1961
+ if ( colorNode !== null ) {
1962
+
1963
+ color = getNode( colorNode );
1964
+
1965
+ }
1966
+
1967
+ break;
1968
+
1969
+ case 'coord':
1970
+ const coordNode = fieldValues[ 0 ];
1971
+
1972
+ if ( coordNode !== null ) {
1973
+
1974
+ coord = getNode( coordNode );
1975
+
1976
+ }
1977
+
1978
+ break;
1979
+
1980
+
1981
+ default:
1982
+ console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
1983
+ break;
1984
+
1985
+ }
1986
+
1987
+ }
1988
+
1989
+ const geometry = new BufferGeometry();
1990
+
1991
+ geometry.setAttribute( 'position', new Float32BufferAttribute( coord, 3 ) );
1992
+
1993
+ if ( color ) {
1994
+
1995
+ const colorAttribute = new Float32BufferAttribute( color, 3 );
1996
+ convertColorsToLinearSRGB( colorAttribute );
1997
+
1998
+ geometry.setAttribute( 'color', colorAttribute );
1999
+
2000
+ }
2001
+
2002
+ geometry._type = 'points';
2003
+
2004
+ return geometry;
2005
+
2006
+ }
2007
+
2008
+ function buildBoxNode( node ) {
2009
+
2010
+ const size = new Vector3( 2, 2, 2 );
2011
+
2012
+ const fields = node.fields;
2013
+
2014
+ for ( let i = 0, l = fields.length; i < l; i ++ ) {
2015
+
2016
+ const field = fields[ i ];
2017
+ const fieldName = field.name;
2018
+ const fieldValues = field.values;
2019
+
2020
+ switch ( fieldName ) {
2021
+
2022
+ case 'size':
2023
+ size.x = fieldValues[ 0 ];
2024
+ size.y = fieldValues[ 1 ];
2025
+ size.z = fieldValues[ 2 ];
2026
+ break;
2027
+
2028
+ default:
2029
+ console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
2030
+ break;
2031
+
2032
+ }
2033
+
2034
+ }
2035
+
2036
+ const geometry = new BoxGeometry( size.x, size.y, size.z );
2037
+
2038
+ return geometry;
2039
+
2040
+ }
2041
+
2042
+ function buildConeNode( node ) {
2043
+
2044
+ let radius = 1, height = 2, openEnded = false;
2045
+
2046
+ const fields = node.fields;
2047
+
2048
+ for ( let i = 0, l = fields.length; i < l; i ++ ) {
2049
+
2050
+ const field = fields[ i ];
2051
+ const fieldName = field.name;
2052
+ const fieldValues = field.values;
2053
+
2054
+ switch ( fieldName ) {
2055
+
2056
+ case 'bottom':
2057
+ openEnded = ! fieldValues[ 0 ];
2058
+ break;
2059
+
2060
+ case 'bottomRadius':
2061
+ radius = fieldValues[ 0 ];
2062
+ break;
2063
+
2064
+ case 'height':
2065
+ height = fieldValues[ 0 ];
2066
+ break;
2067
+
2068
+ case 'side':
2069
+ // field not supported
2070
+ break;
2071
+
2072
+ default:
2073
+ console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
2074
+ break;
2075
+
2076
+ }
2077
+
2078
+ }
2079
+
2080
+ const geometry = new ConeGeometry( radius, height, 16, 1, openEnded );
2081
+
2082
+ return geometry;
2083
+
2084
+ }
2085
+
2086
+ function buildCylinderNode( node ) {
2087
+
2088
+ let radius = 1, height = 2;
2089
+
2090
+ const fields = node.fields;
2091
+
2092
+ for ( let i = 0, l = fields.length; i < l; i ++ ) {
2093
+
2094
+ const field = fields[ i ];
2095
+ const fieldName = field.name;
2096
+ const fieldValues = field.values;
2097
+
2098
+ switch ( fieldName ) {
2099
+
2100
+ case 'bottom':
2101
+ // field not supported
2102
+ break;
2103
+
2104
+ case 'radius':
2105
+ radius = fieldValues[ 0 ];
2106
+ break;
2107
+
2108
+ case 'height':
2109
+ height = fieldValues[ 0 ];
2110
+ break;
2111
+
2112
+ case 'side':
2113
+ // field not supported
2114
+ break;
2115
+
2116
+ case 'top':
2117
+ // field not supported
2118
+ break;
2119
+
2120
+ default:
2121
+ console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
2122
+ break;
2123
+
2124
+ }
2125
+
2126
+ }
2127
+
2128
+ const geometry = new CylinderGeometry( radius, radius, height, 16, 1 );
2129
+
2130
+ return geometry;
2131
+
2132
+ }
2133
+
2134
+ function buildSphereNode( node ) {
2135
+
2136
+ let radius = 1;
2137
+
2138
+ const fields = node.fields;
2139
+
2140
+ for ( let i = 0, l = fields.length; i < l; i ++ ) {
2141
+
2142
+ const field = fields[ i ];
2143
+ const fieldName = field.name;
2144
+ const fieldValues = field.values;
2145
+
2146
+ switch ( fieldName ) {
2147
+
2148
+ case 'radius':
2149
+ radius = fieldValues[ 0 ];
2150
+ break;
2151
+
2152
+ default:
2153
+ console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
2154
+ break;
2155
+
2156
+ }
2157
+
2158
+ }
2159
+
2160
+ const geometry = new SphereGeometry( radius, 16, 16 );
2161
+
2162
+ return geometry;
2163
+
2164
+ }
2165
+
2166
+ function buildElevationGridNode( node ) {
2167
+
2168
+ let color;
2169
+ let normal;
2170
+ let texCoord;
2171
+ let height;
2172
+
2173
+ let colorPerVertex = true;
2174
+ let normalPerVertex = true;
2175
+ let solid = true;
2176
+ let ccw = true;
2177
+ let creaseAngle = 0;
2178
+ let xDimension = 2;
2179
+ let zDimension = 2;
2180
+ let xSpacing = 1;
2181
+ let zSpacing = 1;
2182
+
2183
+ const fields = node.fields;
2184
+
2185
+ for ( let i = 0, l = fields.length; i < l; i ++ ) {
2186
+
2187
+ const field = fields[ i ];
2188
+ const fieldName = field.name;
2189
+ const fieldValues = field.values;
2190
+
2191
+ switch ( fieldName ) {
2192
+
2193
+ case 'color':
2194
+ const colorNode = fieldValues[ 0 ];
2195
+
2196
+ if ( colorNode !== null ) {
2197
+
2198
+ color = getNode( colorNode );
2199
+
2200
+ }
2201
+
2202
+ break;
2203
+
2204
+ case 'normal':
2205
+ const normalNode = fieldValues[ 0 ];
2206
+
2207
+ if ( normalNode !== null ) {
2208
+
2209
+ normal = getNode( normalNode );
2210
+
2211
+ }
2212
+
2213
+ break;
2214
+
2215
+ case 'texCoord':
2216
+ const texCoordNode = fieldValues[ 0 ];
2217
+
2218
+ if ( texCoordNode !== null ) {
2219
+
2220
+ texCoord = getNode( texCoordNode );
2221
+
2222
+ }
2223
+
2224
+ break;
2225
+
2226
+ case 'height':
2227
+ height = fieldValues;
2228
+ break;
2229
+
2230
+ case 'ccw':
2231
+ ccw = fieldValues[ 0 ];
2232
+ break;
2233
+
2234
+ case 'colorPerVertex':
2235
+ colorPerVertex = fieldValues[ 0 ];
2236
+ break;
2237
+
2238
+ case 'creaseAngle':
2239
+ creaseAngle = fieldValues[ 0 ];
2240
+ break;
2241
+
2242
+ case 'normalPerVertex':
2243
+ normalPerVertex = fieldValues[ 0 ];
2244
+ break;
2245
+
2246
+ case 'solid':
2247
+ solid = fieldValues[ 0 ];
2248
+ break;
2249
+
2250
+ case 'xDimension':
2251
+ xDimension = fieldValues[ 0 ];
2252
+ break;
2253
+
2254
+ case 'xSpacing':
2255
+ xSpacing = fieldValues[ 0 ];
2256
+ break;
2257
+
2258
+ case 'zDimension':
2259
+ zDimension = fieldValues[ 0 ];
2260
+ break;
2261
+
2262
+ case 'zSpacing':
2263
+ zSpacing = fieldValues[ 0 ];
2264
+ break;
2265
+
2266
+ default:
2267
+ console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
2268
+ break;
2269
+
2270
+ }
2271
+
2272
+ }
2273
+
2274
+ // vertex data
2275
+
2276
+ const vertices = [];
2277
+ const normals = [];
2278
+ const colors = [];
2279
+ const uvs = [];
2280
+
2281
+ for ( let i = 0; i < zDimension; i ++ ) {
2282
+
2283
+ for ( let j = 0; j < xDimension; j ++ ) {
2284
+
2285
+ // compute a row major index
2286
+
2287
+ const index = ( i * xDimension ) + j;
2288
+
2289
+ // vertices
2290
+
2291
+ const x = xSpacing * i;
2292
+ const y = height[ index ];
2293
+ const z = zSpacing * j;
2294
+
2295
+ vertices.push( x, y, z );
2296
+
2297
+ // colors
2298
+
2299
+ if ( color && colorPerVertex === true ) {
2300
+
2301
+ const r = color[ index * 3 + 0 ];
2302
+ const g = color[ index * 3 + 1 ];
2303
+ const b = color[ index * 3 + 2 ];
2304
+
2305
+ colors.push( r, g, b );
2306
+
2307
+ }
2308
+
2309
+ // normals
2310
+
2311
+ if ( normal && normalPerVertex === true ) {
2312
+
2313
+ const xn = normal[ index * 3 + 0 ];
2314
+ const yn = normal[ index * 3 + 1 ];
2315
+ const zn = normal[ index * 3 + 2 ];
2316
+
2317
+ normals.push( xn, yn, zn );
2318
+
2319
+ }
2320
+
2321
+ // uvs
2322
+
2323
+ if ( texCoord ) {
2324
+
2325
+ const s = texCoord[ index * 2 + 0 ];
2326
+ const t = texCoord[ index * 2 + 1 ];
2327
+
2328
+ uvs.push( s, t );
2329
+
2330
+
2331
+ } else {
2332
+
2333
+ uvs.push( i / ( xDimension - 1 ), j / ( zDimension - 1 ) );
2334
+
2335
+ }
2336
+
2337
+ }
2338
+
2339
+ }
2340
+
2341
+ // indices
2342
+
2343
+ const indices = [];
2344
+
2345
+ for ( let i = 0; i < xDimension - 1; i ++ ) {
2346
+
2347
+ for ( let j = 0; j < zDimension - 1; j ++ ) {
2348
+
2349
+ // from https://tecfa.unige.ch/guides/vrml/vrml97/spec/part1/nodesRef.html#ElevationGrid
2350
+
2351
+ const a = i + j * xDimension;
2352
+ const b = i + ( j + 1 ) * xDimension;
2353
+ const c = ( i + 1 ) + ( j + 1 ) * xDimension;
2354
+ const d = ( i + 1 ) + j * xDimension;
2355
+
2356
+ // faces
2357
+
2358
+ if ( ccw === true ) {
2359
+
2360
+ indices.push( a, c, b );
2361
+ indices.push( c, a, d );
2362
+
2363
+ } else {
2364
+
2365
+ indices.push( a, b, c );
2366
+ indices.push( c, d, a );
2367
+
2368
+ }
2369
+
2370
+ }
2371
+
2372
+ }
2373
+
2374
+ //
2375
+
2376
+ const positionAttribute = toNonIndexedAttribute( indices, new Float32BufferAttribute( vertices, 3 ) );
2377
+ const uvAttribute = toNonIndexedAttribute( indices, new Float32BufferAttribute( uvs, 2 ) );
2378
+ let colorAttribute;
2379
+ let normalAttribute;
2380
+
2381
+ // color attribute
2382
+
2383
+ if ( color ) {
2384
+
2385
+ if ( colorPerVertex === false ) {
2386
+
2387
+ for ( let i = 0; i < xDimension - 1; i ++ ) {
2388
+
2389
+ for ( let j = 0; j < zDimension - 1; j ++ ) {
2390
+
2391
+ const index = i + j * ( xDimension - 1 );
2392
+
2393
+ const r = color[ index * 3 + 0 ];
2394
+ const g = color[ index * 3 + 1 ];
2395
+ const b = color[ index * 3 + 2 ];
2396
+
2397
+ // one color per quad
2398
+
2399
+ colors.push( r, g, b ); colors.push( r, g, b ); colors.push( r, g, b );
2400
+ colors.push( r, g, b ); colors.push( r, g, b ); colors.push( r, g, b );
2401
+
2402
+ }
2403
+
2404
+ }
2405
+
2406
+ colorAttribute = new Float32BufferAttribute( colors, 3 );
2407
+
2408
+ } else {
2409
+
2410
+ colorAttribute = toNonIndexedAttribute( indices, new Float32BufferAttribute( colors, 3 ) );
2411
+
2412
+ }
2413
+
2414
+ convertColorsToLinearSRGB( colorAttribute );
2415
+
2416
+ }
2417
+
2418
+ // normal attribute
2419
+
2420
+ if ( normal ) {
2421
+
2422
+ if ( normalPerVertex === false ) {
2423
+
2424
+ for ( let i = 0; i < xDimension - 1; i ++ ) {
2425
+
2426
+ for ( let j = 0; j < zDimension - 1; j ++ ) {
2427
+
2428
+ const index = i + j * ( xDimension - 1 );
2429
+
2430
+ const xn = normal[ index * 3 + 0 ];
2431
+ const yn = normal[ index * 3 + 1 ];
2432
+ const zn = normal[ index * 3 + 2 ];
2433
+
2434
+ // one normal per quad
2435
+
2436
+ normals.push( xn, yn, zn ); normals.push( xn, yn, zn ); normals.push( xn, yn, zn );
2437
+ normals.push( xn, yn, zn ); normals.push( xn, yn, zn ); normals.push( xn, yn, zn );
2438
+
2439
+ }
2440
+
2441
+ }
2442
+
2443
+ normalAttribute = new Float32BufferAttribute( normals, 3 );
2444
+
2445
+ } else {
2446
+
2447
+ normalAttribute = toNonIndexedAttribute( indices, new Float32BufferAttribute( normals, 3 ) );
2448
+
2449
+ }
2450
+
2451
+ } else {
2452
+
2453
+ normalAttribute = computeNormalAttribute( indices, vertices, creaseAngle );
2454
+
2455
+ }
2456
+
2457
+ // build geometry
2458
+
2459
+ const geometry = new BufferGeometry();
2460
+ geometry.setAttribute( 'position', positionAttribute );
2461
+ geometry.setAttribute( 'normal', normalAttribute );
2462
+ geometry.setAttribute( 'uv', uvAttribute );
2463
+
2464
+ if ( colorAttribute ) geometry.setAttribute( 'color', colorAttribute );
2465
+
2466
+ // "solid" influences the material so let's store it for later use
2467
+
2468
+ geometry._solid = solid;
2469
+ geometry._type = 'mesh';
2470
+
2471
+ return geometry;
2472
+
2473
+ }
2474
+
2475
+ function buildExtrusionNode( node ) {
2476
+
2477
+ let crossSection = [ 1, 1, 1, - 1, - 1, - 1, - 1, 1, 1, 1 ];
2478
+ let spine = [ 0, 0, 0, 0, 1, 0 ];
2479
+ let scale;
2480
+ let orientation;
2481
+
2482
+ let beginCap = true;
2483
+ let ccw = true;
2484
+ let creaseAngle = 0;
2485
+ let endCap = true;
2486
+ let solid = true;
2487
+
2488
+ const fields = node.fields;
2489
+
2490
+ for ( let i = 0, l = fields.length; i < l; i ++ ) {
2491
+
2492
+ const field = fields[ i ];
2493
+ const fieldName = field.name;
2494
+ const fieldValues = field.values;
2495
+
2496
+ switch ( fieldName ) {
2497
+
2498
+ case 'beginCap':
2499
+ beginCap = fieldValues[ 0 ];
2500
+ break;
2501
+
2502
+ case 'ccw':
2503
+ ccw = fieldValues[ 0 ];
2504
+ break;
2505
+
2506
+ case 'convex':
2507
+ // field not supported
2508
+ break;
2509
+
2510
+ case 'creaseAngle':
2511
+ creaseAngle = fieldValues[ 0 ];
2512
+ break;
2513
+
2514
+ case 'crossSection':
2515
+ crossSection = fieldValues;
2516
+ break;
2517
+
2518
+ case 'endCap':
2519
+ endCap = fieldValues[ 0 ];
2520
+ break;
2521
+
2522
+ case 'orientation':
2523
+ orientation = fieldValues;
2524
+ break;
2525
+
2526
+ case 'scale':
2527
+ scale = fieldValues;
2528
+ break;
2529
+
2530
+ case 'solid':
2531
+ solid = fieldValues[ 0 ];
2532
+ break;
2533
+
2534
+ case 'spine':
2535
+ spine = fieldValues; // only extrusion along the Y-axis are supported so far
2536
+ break;
2537
+
2538
+ default:
2539
+ console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
2540
+ break;
2541
+
2542
+ }
2543
+
2544
+ }
2545
+
2546
+ const crossSectionClosed = ( crossSection[ 0 ] === crossSection[ crossSection.length - 2 ] && crossSection[ 1 ] === crossSection[ crossSection.length - 1 ] );
2547
+
2548
+ // vertices
2549
+
2550
+ const vertices = [];
2551
+ const spineVector = new Vector3();
2552
+ const scaling = new Vector3();
2553
+
2554
+ const axis = new Vector3();
2555
+ const vertex = new Vector3();
2556
+ const quaternion = new Quaternion();
2557
+
2558
+ for ( let i = 0, j = 0, o = 0, il = spine.length; i < il; i += 3, j += 2, o += 4 ) {
2559
+
2560
+ spineVector.fromArray( spine, i );
2561
+
2562
+ scaling.x = scale ? scale[ j + 0 ] : 1;
2563
+ scaling.y = 1;
2564
+ scaling.z = scale ? scale[ j + 1 ] : 1;
2565
+
2566
+ axis.x = orientation ? orientation[ o + 0 ] : 0;
2567
+ axis.y = orientation ? orientation[ o + 1 ] : 0;
2568
+ axis.z = orientation ? orientation[ o + 2 ] : 1;
2569
+ const angle = orientation ? orientation[ o + 3 ] : 0;
2570
+
2571
+ for ( let k = 0, kl = crossSection.length; k < kl; k += 2 ) {
2572
+
2573
+ vertex.x = crossSection[ k + 0 ];
2574
+ vertex.y = 0;
2575
+ vertex.z = crossSection[ k + 1 ];
2576
+
2577
+ // scale
2578
+
2579
+ vertex.multiply( scaling );
2580
+
2581
+ // rotate
2582
+
2583
+ quaternion.setFromAxisAngle( axis, angle );
2584
+ vertex.applyQuaternion( quaternion );
2585
+
2586
+ // translate
2587
+
2588
+ vertex.add( spineVector );
2589
+
2590
+ vertices.push( vertex.x, vertex.y, vertex.z );
2591
+
2592
+ }
2593
+
2594
+ }
2595
+
2596
+ // indices
2597
+
2598
+ const indices = [];
2599
+
2600
+ const spineCount = spine.length / 3;
2601
+ const crossSectionCount = crossSection.length / 2;
2602
+
2603
+ for ( let i = 0; i < spineCount - 1; i ++ ) {
2604
+
2605
+ for ( let j = 0; j < crossSectionCount - 1; j ++ ) {
2606
+
2607
+ const a = j + i * crossSectionCount;
2608
+ let b = ( j + 1 ) + i * crossSectionCount;
2609
+ const c = j + ( i + 1 ) * crossSectionCount;
2610
+ let d = ( j + 1 ) + ( i + 1 ) * crossSectionCount;
2611
+
2612
+ if ( ( j === crossSectionCount - 2 ) && ( crossSectionClosed === true ) ) {
2613
+
2614
+ b = i * crossSectionCount;
2615
+ d = ( i + 1 ) * crossSectionCount;
2616
+
2617
+ }
2618
+
2619
+ if ( ccw === true ) {
2620
+
2621
+ indices.push( a, b, c );
2622
+ indices.push( c, b, d );
2623
+
2624
+ } else {
2625
+
2626
+ indices.push( a, c, b );
2627
+ indices.push( c, d, b );
2628
+
2629
+ }
2630
+
2631
+ }
2632
+
2633
+ }
2634
+
2635
+ // triangulate cap
2636
+
2637
+ if ( beginCap === true || endCap === true ) {
2638
+
2639
+ const contour = [];
2640
+
2641
+ for ( let i = 0, l = crossSection.length; i < l; i += 2 ) {
2642
+
2643
+ contour.push( new Vector2( crossSection[ i ], crossSection[ i + 1 ] ) );
2644
+
2645
+ }
2646
+
2647
+ const faces = ShapeUtils.triangulateShape( contour, [] );
2648
+ const capIndices = [];
2649
+
2650
+ for ( let i = 0, l = faces.length; i < l; i ++ ) {
2651
+
2652
+ const face = faces[ i ];
2653
+
2654
+ capIndices.push( face[ 0 ], face[ 1 ], face[ 2 ] );
2655
+
2656
+ }
2657
+
2658
+ // begin cap
2659
+
2660
+ if ( beginCap === true ) {
2661
+
2662
+ for ( let i = 0, l = capIndices.length; i < l; i += 3 ) {
2663
+
2664
+ if ( ccw === true ) {
2665
+
2666
+ indices.push( capIndices[ i + 0 ], capIndices[ i + 1 ], capIndices[ i + 2 ] );
2667
+
2668
+ } else {
2669
+
2670
+ indices.push( capIndices[ i + 0 ], capIndices[ i + 2 ], capIndices[ i + 1 ] );
2671
+
2672
+ }
2673
+
2674
+ }
2675
+
2676
+ }
2677
+
2678
+ // end cap
2679
+
2680
+ if ( endCap === true ) {
2681
+
2682
+ const indexOffset = crossSectionCount * ( spineCount - 1 ); // references to the first vertex of the last cross section
2683
+
2684
+ for ( let i = 0, l = capIndices.length; i < l; i += 3 ) {
2685
+
2686
+ if ( ccw === true ) {
2687
+
2688
+ indices.push( indexOffset + capIndices[ i + 0 ], indexOffset + capIndices[ i + 2 ], indexOffset + capIndices[ i + 1 ] );
2689
+
2690
+ } else {
2691
+
2692
+ indices.push( indexOffset + capIndices[ i + 0 ], indexOffset + capIndices[ i + 1 ], indexOffset + capIndices[ i + 2 ] );
2693
+
2694
+ }
2695
+
2696
+ }
2697
+
2698
+ }
2699
+
2700
+ }
2701
+
2702
+ const positionAttribute = toNonIndexedAttribute( indices, new Float32BufferAttribute( vertices, 3 ) );
2703
+ const normalAttribute = computeNormalAttribute( indices, vertices, creaseAngle );
2704
+
2705
+ const geometry = new BufferGeometry();
2706
+ geometry.setAttribute( 'position', positionAttribute );
2707
+ geometry.setAttribute( 'normal', normalAttribute );
2708
+ // no uvs yet
2709
+
2710
+ // "solid" influences the material so let's store it for later use
2711
+
2712
+ geometry._solid = solid;
2713
+ geometry._type = 'mesh';
2714
+
2715
+ return geometry;
2716
+
2717
+ }
2718
+
2719
+ // helper functions
2720
+
2721
+ function resolveUSE( identifier ) {
2722
+
2723
+ const node = nodeMap[ identifier ];
2724
+ const build = getNode( node );
2725
+
2726
+ // because the same 3D objects can have different transformations, it's necessary to clone them.
2727
+ // materials can be influenced by the geometry (e.g. vertex normals). cloning is necessary to avoid
2728
+ // any side effects
2729
+
2730
+ return ( build.isObject3D || build.isMaterial ) ? build.clone() : build;
2731
+
2732
+ }
2733
+
2734
+ function parseFieldChildren( children, owner ) {
2735
+
2736
+ for ( let i = 0, l = children.length; i < l; i ++ ) {
2737
+
2738
+ const object = getNode( children[ i ] );
2739
+
2740
+ if ( object instanceof Object3D ) owner.add( object );
2741
+
2742
+ }
2743
+
2744
+ }
2745
+
2746
+ function triangulateFaceIndex( index, ccw ) {
2747
+
2748
+ const indices = [];
2749
+
2750
+ // since face defintions can have more than three vertices, it's necessary to
2751
+ // perform a simple triangulation
2752
+
2753
+ let start = 0;
2754
+
2755
+ for ( let i = 0, l = index.length; i < l; i ++ ) {
2756
+
2757
+ const i1 = index[ start ];
2758
+ const i2 = index[ i + ( ccw ? 1 : 2 ) ];
2759
+ const i3 = index[ i + ( ccw ? 2 : 1 ) ];
2760
+
2761
+ indices.push( i1, i2, i3 );
2762
+
2763
+ // an index of -1 indicates that the current face has ended and the next one begins
2764
+
2765
+ if ( index[ i + 3 ] === - 1 || i + 3 >= l ) {
2766
+
2767
+ i += 3;
2768
+ start = i + 1;
2769
+
2770
+ }
2771
+
2772
+ }
2773
+
2774
+ return indices;
2775
+
2776
+ }
2777
+
2778
+ function triangulateFaceData( data, index ) {
2779
+
2780
+ const triangulatedData = [];
2781
+
2782
+ let start = 0;
2783
+
2784
+ for ( let i = 0, l = index.length; i < l; i ++ ) {
2785
+
2786
+ const stride = start * 3;
2787
+
2788
+ const x = data[ stride ];
2789
+ const y = data[ stride + 1 ];
2790
+ const z = data[ stride + 2 ];
2791
+
2792
+ triangulatedData.push( x, y, z );
2793
+
2794
+ // an index of -1 indicates that the current face has ended and the next one begins
2795
+
2796
+ if ( index[ i + 3 ] === - 1 || i + 3 >= l ) {
2797
+
2798
+ i += 3;
2799
+ start ++;
2800
+
2801
+ }
2802
+
2803
+ }
2804
+
2805
+ return triangulatedData;
2806
+
2807
+ }
2808
+
2809
+ function flattenData( data, index ) {
2810
+
2811
+ const flattenData = [];
2812
+
2813
+ for ( let i = 0, l = index.length; i < l; i ++ ) {
2814
+
2815
+ const i1 = index[ i ];
2816
+
2817
+ const stride = i1 * 3;
2818
+
2819
+ const x = data[ stride ];
2820
+ const y = data[ stride + 1 ];
2821
+ const z = data[ stride + 2 ];
2822
+
2823
+ flattenData.push( x, y, z );
2824
+
2825
+ }
2826
+
2827
+ return flattenData;
2828
+
2829
+ }
2830
+
2831
+ function expandLineIndex( index ) {
2832
+
2833
+ const indices = [];
2834
+
2835
+ for ( let i = 0, l = index.length; i < l; i ++ ) {
2836
+
2837
+ const i1 = index[ i ];
2838
+ const i2 = index[ i + 1 ];
2839
+
2840
+ indices.push( i1, i2 );
2841
+
2842
+ // an index of -1 indicates that the current line has ended and the next one begins
2843
+
2844
+ if ( index[ i + 2 ] === - 1 || i + 2 >= l ) {
2845
+
2846
+ i += 2;
2847
+
2848
+ }
2849
+
2850
+ }
2851
+
2852
+ return indices;
2853
+
2854
+ }
2855
+
2856
+ function expandLineData( data, index ) {
2857
+
2858
+ const triangulatedData = [];
2859
+
2860
+ let start = 0;
2861
+
2862
+ for ( let i = 0, l = index.length; i < l; i ++ ) {
2863
+
2864
+ const stride = start * 3;
2865
+
2866
+ const x = data[ stride ];
2867
+ const y = data[ stride + 1 ];
2868
+ const z = data[ stride + 2 ];
2869
+
2870
+ triangulatedData.push( x, y, z );
2871
+
2872
+ // an index of -1 indicates that the current line has ended and the next one begins
2873
+
2874
+ if ( index[ i + 2 ] === - 1 || i + 2 >= l ) {
2875
+
2876
+ i += 2;
2877
+ start ++;
2878
+
2879
+ }
2880
+
2881
+ }
2882
+
2883
+ return triangulatedData;
2884
+
2885
+ }
2886
+
2887
+ const vA = new Vector3();
2888
+ const vB = new Vector3();
2889
+ const vC = new Vector3();
2890
+
2891
+ const uvA = new Vector2();
2892
+ const uvB = new Vector2();
2893
+ const uvC = new Vector2();
2894
+
2895
+ function computeAttributeFromIndexedData( coordIndex, index, data, itemSize ) {
2896
+
2897
+ const array = [];
2898
+
2899
+ // we use the coordIndex.length as delimiter since normalIndex must contain at least as many indices
2900
+
2901
+ for ( let i = 0, l = coordIndex.length; i < l; i += 3 ) {
2902
+
2903
+ const a = index[ i ];
2904
+ const b = index[ i + 1 ];
2905
+ const c = index[ i + 2 ];
2906
+
2907
+ if ( itemSize === 2 ) {
2908
+
2909
+ uvA.fromArray( data, a * itemSize );
2910
+ uvB.fromArray( data, b * itemSize );
2911
+ uvC.fromArray( data, c * itemSize );
2912
+
2913
+ array.push( uvA.x, uvA.y );
2914
+ array.push( uvB.x, uvB.y );
2915
+ array.push( uvC.x, uvC.y );
2916
+
2917
+ } else {
2918
+
2919
+ vA.fromArray( data, a * itemSize );
2920
+ vB.fromArray( data, b * itemSize );
2921
+ vC.fromArray( data, c * itemSize );
2922
+
2923
+ array.push( vA.x, vA.y, vA.z );
2924
+ array.push( vB.x, vB.y, vB.z );
2925
+ array.push( vC.x, vC.y, vC.z );
2926
+
2927
+ }
2928
+
2929
+ }
2930
+
2931
+ return new Float32BufferAttribute( array, itemSize );
2932
+
2933
+ }
2934
+
2935
+ function computeAttributeFromFaceData( index, faceData ) {
2936
+
2937
+ const array = [];
2938
+
2939
+ for ( let i = 0, j = 0, l = index.length; i < l; i += 3, j ++ ) {
2940
+
2941
+ vA.fromArray( faceData, j * 3 );
2942
+
2943
+ array.push( vA.x, vA.y, vA.z );
2944
+ array.push( vA.x, vA.y, vA.z );
2945
+ array.push( vA.x, vA.y, vA.z );
2946
+
2947
+ }
2948
+
2949
+ return new Float32BufferAttribute( array, 3 );
2950
+
2951
+ }
2952
+
2953
+ function computeAttributeFromLineData( index, lineData ) {
2954
+
2955
+ const array = [];
2956
+
2957
+ for ( let i = 0, j = 0, l = index.length; i < l; i += 2, j ++ ) {
2958
+
2959
+ vA.fromArray( lineData, j * 3 );
2960
+
2961
+ array.push( vA.x, vA.y, vA.z );
2962
+ array.push( vA.x, vA.y, vA.z );
2963
+
2964
+ }
2965
+
2966
+ return new Float32BufferAttribute( array, 3 );
2967
+
2968
+ }
2969
+
2970
+ function toNonIndexedAttribute( indices, attribute ) {
2971
+
2972
+ const array = attribute.array;
2973
+ const itemSize = attribute.itemSize;
2974
+
2975
+ const array2 = new array.constructor( indices.length * itemSize );
2976
+
2977
+ let index = 0, index2 = 0;
2978
+
2979
+ for ( let i = 0, l = indices.length; i < l; i ++ ) {
2980
+
2981
+ index = indices[ i ] * itemSize;
2982
+
2983
+ for ( let j = 0; j < itemSize; j ++ ) {
2984
+
2985
+ array2[ index2 ++ ] = array[ index ++ ];
2986
+
2987
+ }
2988
+
2989
+ }
2990
+
2991
+ return new Float32BufferAttribute( array2, itemSize );
2992
+
2993
+ }
2994
+
2995
+ const ab = new Vector3();
2996
+ const cb = new Vector3();
2997
+
2998
+ function computeNormalAttribute( index, coord, creaseAngle ) {
2999
+
3000
+ const faces = [];
3001
+ const vertexNormals = {};
3002
+
3003
+ // prepare face and raw vertex normals
3004
+
3005
+ for ( let i = 0, l = index.length; i < l; i += 3 ) {
3006
+
3007
+ const a = index[ i ];
3008
+ const b = index[ i + 1 ];
3009
+ const c = index[ i + 2 ];
3010
+
3011
+ const face = new Face( a, b, c );
3012
+
3013
+ vA.fromArray( coord, a * 3 );
3014
+ vB.fromArray( coord, b * 3 );
3015
+ vC.fromArray( coord, c * 3 );
3016
+
3017
+ cb.subVectors( vC, vB );
3018
+ ab.subVectors( vA, vB );
3019
+ cb.cross( ab );
3020
+
3021
+ cb.normalize();
3022
+
3023
+ face.normal.copy( cb );
3024
+
3025
+ if ( vertexNormals[ a ] === undefined ) vertexNormals[ a ] = [];
3026
+ if ( vertexNormals[ b ] === undefined ) vertexNormals[ b ] = [];
3027
+ if ( vertexNormals[ c ] === undefined ) vertexNormals[ c ] = [];
3028
+
3029
+ vertexNormals[ a ].push( face.normal );
3030
+ vertexNormals[ b ].push( face.normal );
3031
+ vertexNormals[ c ].push( face.normal );
3032
+
3033
+ faces.push( face );
3034
+
3035
+ }
3036
+
3037
+ // compute vertex normals and build final geometry
3038
+
3039
+ const normals = [];
3040
+
3041
+ for ( let i = 0, l = faces.length; i < l; i ++ ) {
3042
+
3043
+ const face = faces[ i ];
3044
+
3045
+ const nA = weightedNormal( vertexNormals[ face.a ], face.normal, creaseAngle );
3046
+ const nB = weightedNormal( vertexNormals[ face.b ], face.normal, creaseAngle );
3047
+ const nC = weightedNormal( vertexNormals[ face.c ], face.normal, creaseAngle );
3048
+
3049
+ vA.fromArray( coord, face.a * 3 );
3050
+ vB.fromArray( coord, face.b * 3 );
3051
+ vC.fromArray( coord, face.c * 3 );
3052
+
3053
+ normals.push( nA.x, nA.y, nA.z );
3054
+ normals.push( nB.x, nB.y, nB.z );
3055
+ normals.push( nC.x, nC.y, nC.z );
3056
+
3057
+ }
3058
+
3059
+ return new Float32BufferAttribute( normals, 3 );
3060
+
3061
+ }
3062
+
3063
+ function weightedNormal( normals, vector, creaseAngle ) {
3064
+
3065
+ const normal = new Vector3();
3066
+
3067
+ if ( creaseAngle === 0 ) {
3068
+
3069
+ normal.copy( vector );
3070
+
3071
+ } else {
3072
+
3073
+ for ( let i = 0, l = normals.length; i < l; i ++ ) {
3074
+
3075
+ if ( normals[ i ].angleTo( vector ) < creaseAngle ) {
3076
+
3077
+ normal.add( normals[ i ] );
3078
+
3079
+ }
3080
+
3081
+ }
3082
+
3083
+ }
3084
+
3085
+ return normal.normalize();
3086
+
3087
+ }
3088
+
3089
+ function toColorArray( colors ) {
3090
+
3091
+ const array = [];
3092
+
3093
+ for ( let i = 0, l = colors.length; i < l; i += 3 ) {
3094
+
3095
+ array.push( new Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
3096
+
3097
+ }
3098
+
3099
+ return array;
3100
+
3101
+ }
3102
+
3103
+ function convertColorsToLinearSRGB( attribute ) {
3104
+
3105
+ const color = new Color();
3106
+
3107
+ for ( let i = 0; i < attribute.count; i ++ ) {
3108
+
3109
+ color.fromBufferAttribute( attribute, i );
3110
+ color.convertSRGBToLinear();
3111
+
3112
+ attribute.setXYZ( i, color.r, color.g, color.b );
3113
+
3114
+ }
3115
+
3116
+ }
3117
+
3118
+ /**
3119
+ * Vertically paints the faces interpolating between the
3120
+ * specified colors at the specified angels. This is used for the Background
3121
+ * node, but could be applied to other nodes with multiple faces as well.
3122
+ *
3123
+ * When used with the Background node, default is directionIsDown is true if
3124
+ * interpolating the skyColor down from the Zenith. When interpolationg up from
3125
+ * the Nadir i.e. interpolating the groundColor, the directionIsDown is false.
3126
+ *
3127
+ * The first angle is never specified, it is the Zenith (0 rad). Angles are specified
3128
+ * in radians. The geometry is thought a sphere, but could be anything. The color interpolation
3129
+ * is linear along the Y axis in any case.
3130
+ *
3131
+ * You must specify one more color than you have angles at the beginning of the colors array.
3132
+ * This is the color of the Zenith (the top of the shape).
3133
+ *
3134
+ * @param {BufferGeometry} geometry
3135
+ * @param {number} radius
3136
+ * @param {array} angles
3137
+ * @param {array} colors
3138
+ * @param {boolean} topDown - Whether to work top down or bottom up.
3139
+ */
3140
+ function paintFaces( geometry, radius, angles, colors, topDown ) {
3141
+
3142
+ // compute threshold values
3143
+
3144
+ const thresholds = [];
3145
+ const startAngle = ( topDown === true ) ? 0 : Math.PI;
3146
+
3147
+ for ( let i = 0, l = colors.length; i < l; i ++ ) {
3148
+
3149
+ let angle = ( i === 0 ) ? 0 : angles[ i - 1 ];
3150
+ angle = ( topDown === true ) ? angle : ( startAngle - angle );
3151
+
3152
+ const point = new Vector3();
3153
+ point.setFromSphericalCoords( radius, angle, 0 );
3154
+
3155
+ thresholds.push( point );
3156
+
3157
+ }
3158
+
3159
+ // generate vertex colors
3160
+
3161
+ const indices = geometry.index;
3162
+ const positionAttribute = geometry.attributes.position;
3163
+ const colorAttribute = new BufferAttribute( new Float32Array( geometry.attributes.position.count * 3 ), 3 );
3164
+
3165
+ const position = new Vector3();
3166
+ const color = new Color();
3167
+
3168
+ for ( let i = 0; i < indices.count; i ++ ) {
3169
+
3170
+ const index = indices.getX( i );
3171
+ position.fromBufferAttribute( positionAttribute, index );
3172
+
3173
+ let thresholdIndexA, thresholdIndexB;
3174
+ let t = 1;
3175
+
3176
+ for ( let j = 1; j < thresholds.length; j ++ ) {
3177
+
3178
+ thresholdIndexA = j - 1;
3179
+ thresholdIndexB = j;
3180
+
3181
+ const thresholdA = thresholds[ thresholdIndexA ];
3182
+ const thresholdB = thresholds[ thresholdIndexB ];
3183
+
3184
+ if ( topDown === true ) {
3185
+
3186
+ // interpolation for sky color
3187
+
3188
+ if ( position.y <= thresholdA.y && position.y > thresholdB.y ) {
3189
+
3190
+ t = Math.abs( thresholdA.y - position.y ) / Math.abs( thresholdA.y - thresholdB.y );
3191
+
3192
+ break;
3193
+
3194
+ }
3195
+
3196
+ } else {
3197
+
3198
+ // interpolation for ground color
3199
+
3200
+ if ( position.y >= thresholdA.y && position.y < thresholdB.y ) {
3201
+
3202
+ t = Math.abs( thresholdA.y - position.y ) / Math.abs( thresholdA.y - thresholdB.y );
3203
+
3204
+ break;
3205
+
3206
+ }
3207
+
3208
+ }
3209
+
3210
+ }
3211
+
3212
+ const colorA = colors[ thresholdIndexA ];
3213
+ const colorB = colors[ thresholdIndexB ];
3214
+
3215
+ color.copy( colorA ).lerp( colorB, t ).convertSRGBToLinear();
3216
+
3217
+ colorAttribute.setXYZ( index, color.r, color.g, color.b );
3218
+
3219
+ }
3220
+
3221
+ geometry.setAttribute( 'color', colorAttribute );
3222
+
3223
+ }
3224
+
3225
+ //
3226
+
3227
+ const textureLoader = new TextureLoader( this.manager );
3228
+ textureLoader.setPath( this.resourcePath || path ).setCrossOrigin( this.crossOrigin );
3229
+
3230
+ // check version (only 2.0 is supported)
3231
+
3232
+ if ( data.indexOf( '#VRML V2.0' ) === - 1 ) {
3233
+
3234
+ throw Error( 'THREE.VRMLLexer: Version of VRML asset not supported.' );
3235
+
3236
+ }
3237
+
3238
+ // create JSON representing the tree structure of the VRML asset
3239
+
3240
+ const tree = generateVRMLTree( data );
3241
+
3242
+ // parse the tree structure to a three.js scene
3243
+
3244
+ const scene = parseTree( tree );
3245
+
3246
+ return scene;
3247
+
3248
+ }
3249
+
3250
+ }
3251
+
3252
+ class VRMLLexer {
3253
+
3254
+ constructor( tokens ) {
3255
+
3256
+ this.lexer = new chevrotain.Lexer( tokens );
3257
+
3258
+ }
3259
+
3260
+ lex( inputText ) {
3261
+
3262
+ const lexingResult = this.lexer.tokenize( inputText );
3263
+
3264
+ if ( lexingResult.errors.length > 0 ) {
3265
+
3266
+ console.error( lexingResult.errors );
3267
+
3268
+ throw Error( 'THREE.VRMLLexer: Lexing errors detected.' );
3269
+
3270
+ }
3271
+
3272
+ return lexingResult;
3273
+
3274
+ }
3275
+
3276
+ }
3277
+
3278
+ const CstParser = chevrotain.CstParser;
3279
+
3280
+ class VRMLParser extends CstParser {
3281
+
3282
+ constructor( tokenVocabulary ) {
3283
+
3284
+ super( tokenVocabulary );
3285
+
3286
+ const $ = this;
3287
+
3288
+ const Version = tokenVocabulary[ 'Version' ];
3289
+ const LCurly = tokenVocabulary[ 'LCurly' ];
3290
+ const RCurly = tokenVocabulary[ 'RCurly' ];
3291
+ const LSquare = tokenVocabulary[ 'LSquare' ];
3292
+ const RSquare = tokenVocabulary[ 'RSquare' ];
3293
+ const Identifier = tokenVocabulary[ 'Identifier' ];
3294
+ const RouteIdentifier = tokenVocabulary[ 'RouteIdentifier' ];
3295
+ const StringLiteral = tokenVocabulary[ 'StringLiteral' ];
3296
+ const HexLiteral = tokenVocabulary[ 'HexLiteral' ];
3297
+ const NumberLiteral = tokenVocabulary[ 'NumberLiteral' ];
3298
+ const TrueLiteral = tokenVocabulary[ 'TrueLiteral' ];
3299
+ const FalseLiteral = tokenVocabulary[ 'FalseLiteral' ];
3300
+ const NullLiteral = tokenVocabulary[ 'NullLiteral' ];
3301
+ const DEF = tokenVocabulary[ 'DEF' ];
3302
+ const USE = tokenVocabulary[ 'USE' ];
3303
+ const ROUTE = tokenVocabulary[ 'ROUTE' ];
3304
+ const TO = tokenVocabulary[ 'TO' ];
3305
+ const NodeName = tokenVocabulary[ 'NodeName' ];
3306
+
3307
+ $.RULE( 'vrml', function () {
3308
+
3309
+ $.SUBRULE( $.version );
3310
+ $.AT_LEAST_ONE( function () {
3311
+
3312
+ $.SUBRULE( $.node );
3313
+
3314
+ } );
3315
+ $.MANY( function () {
3316
+
3317
+ $.SUBRULE( $.route );
3318
+
3319
+ } );
3320
+
3321
+ } );
3322
+
3323
+ $.RULE( 'version', function () {
3324
+
3325
+ $.CONSUME( Version );
3326
+
3327
+ } );
3328
+
3329
+ $.RULE( 'node', function () {
3330
+
3331
+ $.OPTION( function () {
3332
+
3333
+ $.SUBRULE( $.def );
3334
+
3335
+ } );
3336
+
3337
+ $.CONSUME( NodeName );
3338
+ $.CONSUME( LCurly );
3339
+ $.MANY( function () {
3340
+
3341
+ $.SUBRULE( $.field );
3342
+
3343
+ } );
3344
+ $.CONSUME( RCurly );
3345
+
3346
+ } );
3347
+
3348
+ $.RULE( 'field', function () {
3349
+
3350
+ $.CONSUME( Identifier );
3351
+
3352
+ $.OR2( [
3353
+ { ALT: function () {
3354
+
3355
+ $.SUBRULE( $.singleFieldValue );
3356
+
3357
+ } },
3358
+ { ALT: function () {
3359
+
3360
+ $.SUBRULE( $.multiFieldValue );
3361
+
3362
+ } }
3363
+ ] );
3364
+
3365
+ } );
3366
+
3367
+ $.RULE( 'def', function () {
3368
+
3369
+ $.CONSUME( DEF );
3370
+ $.OR( [
3371
+ { ALT: function () {
3372
+
3373
+ $.CONSUME( Identifier );
3374
+
3375
+ } },
3376
+ { ALT: function () {
3377
+
3378
+ $.CONSUME( NodeName );
3379
+
3380
+ } }
3381
+ ] );
3382
+
3383
+ } );
3384
+
3385
+ $.RULE( 'use', function () {
3386
+
3387
+ $.CONSUME( USE );
3388
+ $.OR( [
3389
+ { ALT: function () {
3390
+
3391
+ $.CONSUME( Identifier );
3392
+
3393
+ } },
3394
+ { ALT: function () {
3395
+
3396
+ $.CONSUME( NodeName );
3397
+
3398
+ } }
3399
+ ] );
3400
+
3401
+ } );
3402
+
3403
+ $.RULE( 'singleFieldValue', function () {
3404
+
3405
+ $.AT_LEAST_ONE( function () {
3406
+
3407
+ $.OR( [
3408
+ { ALT: function () {
3409
+
3410
+ $.SUBRULE( $.node );
3411
+
3412
+ } },
3413
+ { ALT: function () {
3414
+
3415
+ $.SUBRULE( $.use );
3416
+
3417
+ } },
3418
+ { ALT: function () {
3419
+
3420
+ $.CONSUME( StringLiteral );
3421
+
3422
+ } },
3423
+ { ALT: function () {
3424
+
3425
+ $.CONSUME( HexLiteral );
3426
+
3427
+ } },
3428
+ { ALT: function () {
3429
+
3430
+ $.CONSUME( NumberLiteral );
3431
+
3432
+ } },
3433
+ { ALT: function () {
3434
+
3435
+ $.CONSUME( TrueLiteral );
3436
+
3437
+ } },
3438
+ { ALT: function () {
3439
+
3440
+ $.CONSUME( FalseLiteral );
3441
+
3442
+ } },
3443
+ { ALT: function () {
3444
+
3445
+ $.CONSUME( NullLiteral );
3446
+
3447
+ } }
3448
+ ] );
3449
+
3450
+
3451
+ } );
3452
+
3453
+ } );
3454
+
3455
+ $.RULE( 'multiFieldValue', function () {
3456
+
3457
+ $.CONSUME( LSquare );
3458
+ $.MANY( function () {
3459
+
3460
+ $.OR( [
3461
+ { ALT: function () {
3462
+
3463
+ $.SUBRULE( $.node );
3464
+
3465
+ } },
3466
+ { ALT: function () {
3467
+
3468
+ $.SUBRULE( $.use );
3469
+
3470
+ } },
3471
+ { ALT: function () {
3472
+
3473
+ $.CONSUME( StringLiteral );
3474
+
3475
+ } },
3476
+ { ALT: function () {
3477
+
3478
+ $.CONSUME( HexLiteral );
3479
+
3480
+ } },
3481
+ { ALT: function () {
3482
+
3483
+ $.CONSUME( NumberLiteral );
3484
+
3485
+ } },
3486
+ { ALT: function () {
3487
+
3488
+ $.CONSUME( NullLiteral );
3489
+
3490
+ } }
3491
+ ] );
3492
+
3493
+ } );
3494
+ $.CONSUME( RSquare );
3495
+
3496
+ } );
3497
+
3498
+ $.RULE( 'route', function () {
3499
+
3500
+ $.CONSUME( ROUTE );
3501
+ $.CONSUME( RouteIdentifier );
3502
+ $.CONSUME( TO );
3503
+ $.CONSUME2( RouteIdentifier );
3504
+
3505
+ } );
3506
+
3507
+ this.performSelfAnalysis();
3508
+
3509
+ }
3510
+
3511
+ }
3512
+
3513
+ class Face {
3514
+
3515
+ constructor( a, b, c ) {
3516
+
3517
+ this.a = a;
3518
+ this.b = b;
3519
+ this.c = c;
3520
+ this.normal = new Vector3();
3521
+
3522
+ }
3523
+
3524
+ }
3525
+
3526
+ const TEXTURE_TYPE = {
3527
+ INTENSITY: 1,
3528
+ INTENSITY_ALPHA: 2,
3529
+ RGB: 3,
3530
+ RGBA: 4
3531
+ };
3532
+
3533
+ export { VRMLLoader };