@xort/cga 0.0.92 → 0.1.0

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 (369) hide show
  1. package/THIRD_PARTY_NOTICES.md +47 -0
  2. package/build/@xort_cga.js +14209 -14318
  3. package/build/cga.d.ts +2284 -1958
  4. package/build/cga.esm.js +14179 -0
  5. package/dist/THIRD_PARTY_NOTICES.md +47 -0
  6. package/dist/index.cjs +14320 -0
  7. package/dist/index.cjs.map +1 -0
  8. package/dist/index.d.cts +2358 -0
  9. package/dist/index.d.ts +2358 -38
  10. package/dist/index.js +14181 -56
  11. package/dist/index.js.map +1 -0
  12. package/package.json +59 -47
  13. package/readme.md +162 -247
  14. package/.github/FUNDING.yml +0 -12
  15. package/cga/1./347/202/271/344/270/216/347/272/277/346/200/247/345/205/203/347/264/240/347/232/204/350/267/235/347/246/273.html +0 -601
  16. package/cga/1./347/202/271/344/270/216/347/272/277/346/200/247/345/205/203/347/264/240/347/232/204/350/267/235/347/246/273.md +0 -111
  17. package/cga/2./347/202/271/344/270/216/351/235/242/346/200/247/345/205/203/347/264/240.md +0 -4
  18. package/cga/img//347/202/271/344/270/216/345/260/204/347/272/277.png +0 -0
  19. package/cga/img//347/202/271/344/270/216/347/233/264/347/272/277.png +0 -0
  20. package/cga/img//347/202/271/344/270/216/347/272/277/346/256/265.png +0 -0
  21. package/cga/img//347/233/264/347/272/277/347/232/204/350/241/250/350/276/276/345/274/217.png +0 -0
  22. package/deploy.sh +0 -39
  23. package/dist/IKanimation/Bone.d.ts +0 -7
  24. package/dist/IKanimation/Bone.js +0 -20
  25. package/dist/IKanimation/CCDSolver.d.ts +0 -37
  26. package/dist/IKanimation/CCDSolver.js +0 -93
  27. package/dist/IKanimation/Joint.d.ts +0 -3
  28. package/dist/IKanimation/Joint.js +0 -17
  29. package/dist/IKanimation/constaint/constraint.d.ts +0 -10
  30. package/dist/IKanimation/constaint/constraint.js +0 -25
  31. package/dist/IKanimation/constaint/hinge.d.ts +0 -12
  32. package/dist/IKanimation/constaint/hinge.js +0 -46
  33. package/dist/IKanimation/constaint/slider.d.ts +0 -12
  34. package/dist/IKanimation/constaint/slider.js +0 -44
  35. package/dist/IKanimation/index.d.ts +0 -0
  36. package/dist/IKanimation/index.js +0 -9
  37. package/dist/IKanimation/isolver.d.ts +0 -4
  38. package/dist/IKanimation/isolver.js +0 -10
  39. package/dist/IKanimation/skeleton.d.ts +0 -13
  40. package/dist/IKanimation/skeleton.js +0 -31
  41. package/dist/alg/common.d.ts +0 -114
  42. package/dist/alg/common.js +0 -302
  43. package/dist/alg/curve.d.ts +0 -4
  44. package/dist/alg/curve.js +0 -11
  45. package/dist/alg/delaunator.d.ts +0 -29
  46. package/dist/alg/delaunator.js +0 -442
  47. package/dist/alg/delaunay.d.ts +0 -20
  48. package/dist/alg/delaunay.js +0 -199
  49. package/dist/alg/delaunayslow.d.ts +0 -18
  50. package/dist/alg/delaunayslow.js +0 -140
  51. package/dist/alg/extrude/extrude.d.ts +0 -3
  52. package/dist/alg/extrude/extrude.js +0 -17
  53. package/dist/alg/extrude.d.ts +0 -199
  54. package/dist/alg/extrude.js +0 -728
  55. package/dist/alg/offset/index.d.ts +0 -0
  56. package/dist/alg/offset/index.js +0 -9
  57. package/dist/alg/offset.d.ts +0 -0
  58. package/dist/alg/offset.js +0 -472
  59. package/dist/alg/pointset.d.ts +0 -94
  60. package/dist/alg/pointset.js +0 -223
  61. package/dist/alg/recognition.d.ts +0 -14
  62. package/dist/alg/recognition.js +0 -37
  63. package/dist/alg/result.d.ts +0 -22
  64. package/dist/alg/result.js +0 -2
  65. package/dist/alg/segmentset.d.ts +0 -11
  66. package/dist/alg/segmentset.js +0 -45
  67. package/dist/alg/sort.d.ts +0 -2
  68. package/dist/alg/sort.js +0 -14
  69. package/dist/alg/split.d.ts +0 -8
  70. package/dist/alg/split.js +0 -10
  71. package/dist/alg/trianglution.d.ts +0 -15
  72. package/dist/alg/trianglution.js +0 -70
  73. package/dist/alg/vol.d.ts +0 -6
  74. package/dist/alg/vol.js +0 -18
  75. package/dist/alg/voronoi.d.ts +0 -31
  76. package/dist/alg/voronoi.js +0 -418
  77. package/dist/app.d.ts +0 -1
  78. package/dist/app.js +0 -248
  79. package/dist/basic/distance.d.ts +0 -12
  80. package/dist/basic/distance.js +0 -39
  81. package/dist/csg/bsp.d.ts +0 -9
  82. package/dist/csg/bsp.js +0 -22
  83. package/dist/csg/node.d.ts +0 -12
  84. package/dist/csg/node.js +0 -75
  85. package/dist/csg/polygon.d.ts +0 -43
  86. package/dist/csg/polygon.js +0 -161
  87. package/dist/diamondMaterialShader.d.ts +0 -92
  88. package/dist/diamondMaterialShader.js +0 -118
  89. package/dist/effect/breath-light.d.ts +0 -4
  90. package/dist/effect/breath-light.js +0 -39
  91. package/dist/extends/geometryaid.d.ts +0 -28
  92. package/dist/extends/geometryaid.js +0 -71
  93. package/dist/extends/split.d.ts +0 -3
  94. package/dist/extends/split.js +0 -13
  95. package/dist/glview.d.ts +0 -112
  96. package/dist/glview.js +0 -564
  97. package/dist/math/Color.d.ts +0 -33
  98. package/dist/math/Color.js +0 -235
  99. package/dist/math/Euler.d.ts +0 -46
  100. package/dist/math/Euler.js +0 -225
  101. package/dist/math/HVec3.d.ts +0 -43
  102. package/dist/math/HVec3.js +0 -176
  103. package/dist/math/Mat3.d.ts +0 -29
  104. package/dist/math/Mat3.js +0 -244
  105. package/dist/math/Mat4.d.ts +0 -85
  106. package/dist/math/Mat4.js +0 -791
  107. package/dist/math/Math.d.ts +0 -130
  108. package/dist/math/Math.js +0 -198
  109. package/dist/math/Quat.d.ts +0 -82
  110. package/dist/math/Quat.js +0 -418
  111. package/dist/math/Vec2.d.ts +0 -68
  112. package/dist/math/Vec2.js +0 -328
  113. package/dist/math/Vec3.d.ts +0 -240
  114. package/dist/math/Vec3.js +0 -1082
  115. package/dist/math/Vec4.d.ts +0 -81
  116. package/dist/math/Vec4.js +0 -475
  117. package/dist/math/vecs.d.ts +0 -134
  118. package/dist/math/vecs.js +0 -464
  119. package/dist/render/bufferAttribute.d.ts +0 -104
  120. package/dist/render/bufferAttribute.js +0 -344
  121. package/dist/render/geometry.d.ts +0 -87
  122. package/dist/render/geometry.js +0 -769
  123. package/dist/render/mesh.d.ts +0 -30
  124. package/dist/render/mesh.js +0 -87
  125. package/dist/render/types.d.ts +0 -3
  126. package/dist/render/types.js +0 -8
  127. package/dist/robust/plane.d.ts +0 -7
  128. package/dist/robust/plane.js +0 -17
  129. package/dist/robust/vec.d.ts +0 -15
  130. package/dist/robust/vec.js +0 -71
  131. package/dist/struct/3d/Box.d.ts +0 -23
  132. package/dist/struct/3d/Box.js +0 -109
  133. package/dist/struct/3d/Capsule.d.ts +0 -12
  134. package/dist/struct/3d/Capsule.js +0 -36
  135. package/dist/struct/3d/Circle.d.ts +0 -52
  136. package/dist/struct/3d/Circle.js +0 -138
  137. package/dist/struct/3d/Disk.d.ts +0 -10
  138. package/dist/struct/3d/Disk.js +0 -22
  139. package/dist/struct/3d/Frustum.d.ts +0 -35
  140. package/dist/struct/3d/Frustum.js +0 -159
  141. package/dist/struct/3d/Line.d.ts +0 -40
  142. package/dist/struct/3d/Line.js +0 -340
  143. package/dist/struct/3d/Path.d.ts +0 -75
  144. package/dist/struct/3d/Path.js +0 -308
  145. package/dist/struct/3d/Plane.d.ts +0 -74
  146. package/dist/struct/3d/Plane.js +0 -298
  147. package/dist/struct/3d/Point.d.ts +0 -4
  148. package/dist/struct/3d/Point.js +0 -30
  149. package/dist/struct/3d/Polygon.d.ts +0 -8
  150. package/dist/struct/3d/Polygon.js +0 -55
  151. package/dist/struct/3d/Polyline.d.ts +0 -34
  152. package/dist/struct/3d/Polyline.js +0 -130
  153. package/dist/struct/3d/Ray.d.ts +0 -21
  154. package/dist/struct/3d/Ray.js +0 -262
  155. package/dist/struct/3d/Rectangle.d.ts +0 -7
  156. package/dist/struct/3d/Rectangle.js +0 -35
  157. package/dist/struct/3d/Segment.d.ts +0 -32
  158. package/dist/struct/3d/Segment.js +0 -334
  159. package/dist/struct/3d/Shape.d.ts +0 -4
  160. package/dist/struct/3d/Shape.js +0 -27
  161. package/dist/struct/3d/Sphere.d.ts +0 -11
  162. package/dist/struct/3d/Sphere.js +0 -30
  163. package/dist/struct/3d/Triangle.d.ts +0 -8
  164. package/dist/struct/3d/Triangle.js +0 -53
  165. package/dist/struct/bsp.d.ts +0 -9
  166. package/dist/struct/bsp.js +0 -44
  167. package/dist/struct/btree.d.ts +0 -0
  168. package/dist/struct/btree.js +0 -1
  169. package/dist/struct/data/ArrayList.d.ts +0 -42
  170. package/dist/struct/data/ArrayList.js +0 -172
  171. package/dist/struct/data/ArrayObject.d.ts +0 -30
  172. package/dist/struct/data/ArrayObject.js +0 -131
  173. package/dist/struct/data/type.d.ts +0 -13
  174. package/dist/struct/data/type.js +0 -18
  175. package/dist/struct/kdtree.d.ts +0 -0
  176. package/dist/struct/kdtree.js +0 -1
  177. package/dist/struct/polyTree.d.ts +0 -4
  178. package/dist/struct/polyTree.js +0 -27
  179. package/dist/struct/quatTree.d.ts +0 -0
  180. package/dist/struct/quatTree.js +0 -1
  181. package/dist/struct/tree.d.ts +0 -11
  182. package/dist/struct/tree.js +0 -26
  183. package/dist/utils/array.d.ts +0 -24
  184. package/dist/utils/array.js +0 -89
  185. package/dist/utils/types.d.ts +0 -24
  186. package/dist/utils/types.js +0 -20
  187. package/docs/.vuepress/components/distance.vue +0 -125
  188. package/docs/.vuepress/components/intersect.vue +0 -0
  189. package/docs/.vuepress/components/trianglution.vue +0 -121
  190. package/docs/.vuepress/components/utils.js +0 -314
  191. package/docs/.vuepress/config.js +0 -99
  192. package/docs/.vuepress/enhanceApp.js +0 -13
  193. package/docs/.vuepress/public/delaunay.png +0 -0
  194. package/docs/.vuepress/public/logo.png +0 -0
  195. package/docs/.vuepress/public/plane-set-convex.png +0 -0
  196. package/docs/.vuepress/public/sponsor/alipay.jpg +0 -0
  197. package/docs/.vuepress/public/sponsor/wechat.png +0 -0
  198. package/docs/README.md +0 -14
  199. package/docs/demo/README.md +0 -9
  200. package/docs/guide/README.md +0 -94
  201. package/docs/guide/array.md +0 -10
  202. package/docs/guide/cy/trianglution.html +0 -2
  203. package/docs/guide/distLineAll.md +0 -85
  204. package/docs/guide/distPointAll.md +0 -137
  205. package/docs/guide/distRayAll.md +0 -69
  206. package/docs/guide/distSegmentAll.md +0 -19
  207. package/docs/guide/point.vue +0 -12
  208. package/docs/guide/vector.md +0 -10
  209. package/docs/guide//345/270/270/347/224/250.md +0 -156
  210. package/docs/sponsor/README.md +0 -15
  211. package/docs//345/274/200/345/217/221/346/227/245/345/277/227/2020/345/271/2643/346/234/21013/346/227/245.md +0 -6
  212. package/effect/common.glsl +0 -34
  213. package/effect/drawing.glsl +0 -36
  214. package/effect/shape.arc.glsl +0 -13
  215. package/effect/shape.circle.glsl +0 -13
  216. package/effect/shape.grid.glsl +0 -42
  217. package/effect/shape.line.glsl +0 -18
  218. package/effect/shape.pie.glsl +0 -18
  219. package/effect/shape.plot.glsl +0 -10
  220. package/effect/shape.poly.glsl +0 -15
  221. package/effect/shape.rect.glsl +0 -14
  222. package/effect/shape.rectround.glsl +0 -15
  223. package/effect/shape.segment.glsl +0 -10
  224. package/effect/shape.spiral.glsl +0 -12
  225. package/effect/shape.star.glsl +0 -16
  226. package/examples/index.html +0 -31
  227. package/git.sh +0 -12
  228. package/gitproxy.sh +0 -6
  229. package/image/readme/1640758500266.png +0 -0
  230. package/image/readme/1640758513361.png +0 -0
  231. package/index.html +0 -14
  232. package/linear algorithm//346/225/260/345/255/246/350/241/250/350/276/276/345/274/217.md" +0 -122
  233. package/linear algorithm//347/237/251/351/230/265.md" +0 -91
  234. package/rollup.config.js +0 -79
  235. package/scripttest.html +0 -23
  236. package/src/IKanimation/Bone.ts +0 -20
  237. package/src/IKanimation/CCDSolver.ts +0 -114
  238. package/src/IKanimation/Joint.ts +0 -13
  239. package/src/IKanimation/constaint/constraint.ts +0 -23
  240. package/src/IKanimation/constaint/hinge.ts +0 -29
  241. package/src/IKanimation/constaint/slider.ts +0 -25
  242. package/src/IKanimation/index.ts +0 -8
  243. package/src/IKanimation/isolver.ts +0 -13
  244. package/src/IKanimation/skeleton.ts +0 -30
  245. package/src/alg/common.ts +0 -304
  246. package/src/alg/curve.ts +0 -9
  247. package/src/alg/delaunator.ts +0 -519
  248. package/src/alg/delaunay.ts +0 -163
  249. package/src/alg/delaunayslow.ts +0 -183
  250. package/src/alg/extrude/extrude.ts +0 -19
  251. package/src/alg/extrude.ts +0 -941
  252. package/src/alg/offset/index.ts +0 -8
  253. package/src/alg/offset.ts +0 -501
  254. package/src/alg/pointset.ts +0 -219
  255. package/src/alg/recognition.ts +0 -43
  256. package/src/alg/result.ts +0 -24
  257. package/src/alg/segmentset.ts +0 -44
  258. package/src/alg/sort.ts +0 -11
  259. package/src/alg/split.ts +0 -15
  260. package/src/alg/trianglution.ts +0 -53
  261. package/src/alg/vol.ts +0 -18
  262. package/src/alg/voronoi.ts +0 -303
  263. package/src/app.css +0 -12
  264. package/src/app.ts +0 -285
  265. package/src/assets/color.jpg +0 -0
  266. package/src/basic/distance.ts +0 -40
  267. package/src/clipper/clipper.d.ts +0 -323
  268. package/src/clipper/clipper.js +0 -7626
  269. package/src/clipper/clipper_float.js +0 -185
  270. package/src/clipper/clipper_float_unminified.js +0 -5639
  271. package/src/clipper/clipperint.js +0 -7626
  272. package/src/csg/bsp.ts +0 -24
  273. package/src/csg/csg.js +0 -583
  274. package/src/csg/node.ts +0 -91
  275. package/src/csg/polygon.ts +0 -177
  276. package/src/diamondMaterialShader.ts +0 -93
  277. package/src/effect/breath-light.ts +0 -24
  278. package/src/extends/geometryaid.ts +0 -86
  279. package/src/extends/split.ts +0 -15
  280. package/src/glview.ts +0 -570
  281. package/src/index.ts +0 -47
  282. package/src/math/Color.ts +0 -225
  283. package/src/math/Euler.ts +0 -238
  284. package/src/math/HVec3.ts +0 -1144
  285. package/src/math/Mat3.ts +0 -365
  286. package/src/math/Mat4.ts +0 -1134
  287. package/src/math/Math.ts +0 -213
  288. package/src/math/Quat.ts +0 -536
  289. package/src/math/Vec2.ts +0 -408
  290. package/src/math/Vec3.ts +0 -1307
  291. package/src/math/Vec4.ts +0 -587
  292. package/src/math/vecs.ts +0 -486
  293. package/src/render/bufferAttribute.ts +0 -491
  294. package/src/render/geometry.ts +0 -1329
  295. package/src/render/mesh.ts +0 -82
  296. package/src/render/types.ts +0 -17
  297. package/src/robust/plane.ts +0 -12
  298. package/src/robust/readme.md +0 -1
  299. package/src/robust/vec.ts +0 -61
  300. package/src/shader/cga.glsl +0 -202
  301. package/src/shader/common.glsl +0 -87
  302. package/src/shader/noise/GLSL-Noise.md +0 -1108
  303. package/src/shader/noise/cellular2D.glsl +0 -69
  304. package/src/shader/noise/cellular2x2.glsl +0 -64
  305. package/src/shader/noise/cellular2x2x2.glsl +0 -88
  306. package/src/shader/noise/cellular3D.glsl +0 -187
  307. package/src/shader/noise/classicnoise2D.glsl +0 -113
  308. package/src/shader/noise/classicnoise3D.glsl +0 -177
  309. package/src/shader/noise/classicnoise4D.glsl +0 -302
  310. package/src/shader/noise/noise2D.glsl +0 -71
  311. package/src/shader/noise/noise3D.glsl +0 -103
  312. package/src/shader/noise/noise3Dgrad.glsl +0 -111
  313. package/src/shader/noise/noise4D.glsl +0 -129
  314. package/src/shader/noise/psrdnoise2D.glsl +0 -462
  315. package/src/struct/3d/Box.ts +0 -124
  316. package/src/struct/3d/Capsule.ts +0 -18
  317. package/src/struct/3d/Circle.ts +0 -149
  318. package/src/struct/3d/Disk.ts +0 -22
  319. package/src/struct/3d/Frustum.ts +0 -189
  320. package/src/struct/3d/Line.ts +0 -378
  321. package/src/struct/3d/Path.ts +0 -314
  322. package/src/struct/3d/Plane.ts +0 -341
  323. package/src/struct/3d/Point.ts +0 -7
  324. package/src/struct/3d/PolyLine.ts +0 -115
  325. package/src/struct/3d/Polygon.ts +0 -46
  326. package/src/struct/3d/Ray.ts +0 -285
  327. package/src/struct/3d/Rectangle.ts +0 -18
  328. package/src/struct/3d/Segment.ts +0 -330
  329. package/src/struct/3d/Shape.ts +0 -7
  330. package/src/struct/3d/Sphere.ts +0 -31
  331. package/src/struct/3d/Triangle.ts +0 -28
  332. package/src/struct/bsp.ts +0 -18
  333. package/src/struct/btree.ts +0 -0
  334. package/src/struct/data/ArrayList.ts +0 -144
  335. package/src/struct/data/ArrayObject.ts +0 -105
  336. package/src/struct/data/type.ts +0 -14
  337. package/src/struct/kdtree.ts +0 -0
  338. package/src/struct/polyTree.ts +0 -8
  339. package/src/struct/quatTree.ts +0 -0
  340. package/src/struct/tree.ts +0 -30
  341. package/src/utils/array.ts +0 -106
  342. package/src/utils/types.ts +0 -42
  343. package/src-gis/app.ts +0 -7
  344. package/src-gis/core/Cartographic.ts +0 -48
  345. package/src-gis/core/EllipsoidGeodesic.ts +0 -56
  346. package/src-gis/core/EllipsoidTerrainProvider.ts +0 -35
  347. package/src-gis/core/HeightmapTerrainData.ts +0 -5
  348. package/src-gis/core/Rectangle.ts +0 -112
  349. package/src-gis/core/TaskProcessor.ts +0 -222
  350. package/src-gis/gis.ts +0 -25
  351. package/src-gis/globe.ts +0 -54
  352. package/src-gis/math/Cartographic.ts +0 -24
  353. package/src-gis/math/GVec3.ts +0 -55
  354. package/src-gis/math/ellipsoid.ts +0 -13
  355. package/src-gis/provider/DcTerrainProvider.ts +0 -36
  356. package/src-gis/provider/TerrainProvider.ts +0 -12
  357. package/src-gis/scene/DcImageryProvider.ts +0 -36
  358. package/src-gis/scene/GeographicTilingScheme.ts +0 -65
  359. package/src-gis/scene/Globe.ts +0 -76
  360. package/src-gis/scene/GlobeSurfaceShaderSet.ts +0 -9
  361. package/src-gis/scene/GlobeSurfaceTileProvider.ts +0 -25
  362. package/src-gis/scene/ImageryLayerCollection.ts +0 -75
  363. package/src-gis/scene/ImageryProvider.ts +0 -28
  364. package/src-gis/scene/QuadtreeTile.ts +0 -162
  365. package/src-gis/scene/UrlTemplateImageryProvider.ts +0 -32
  366. package/src-gis/scene/quadtree_primitive.ts +0 -58
  367. package/tsconfig.json +0 -77
  368. package/webpack.config.js +0 -112
  369. package//350/256/241/347/256/227/345/207/240/344/275/225/351/227/256/351/242/230.md +0 -26
@@ -1,1329 +0,0 @@
1
- import { Mat3 } from "../math/Mat3";
2
- import { Mat4 } from "../math/Mat4";
3
- import { v3, Vec3 } from "../math/Vec3";
4
- import { Box } from "../struct/3d/Box";
5
- import { Sphere } from "../struct/3d/Sphere";
6
- import { BufferAttribute, Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from "./bufferAttribute";
7
- import { isBufferArray, TypedArray } from "./types";
8
- import { Vec2 } from "../math/Vec2";
9
- import { Vec4 } from "../math/Vec4";
10
- import { vecs } from "../math/vecs";
11
-
12
-
13
- export interface IGeometry {
14
- position: number[];
15
- normal?: number[];
16
- index?: number[];
17
- uv?: number[];
18
- uv2?: number[];
19
- tangent?: number[];
20
- }
21
-
22
- export interface IBufferGeometry {
23
- position: Float32Array | undefined;
24
- index?: Uint32Array | Uint16Array
25
- normal?: Float32Array;
26
- uv?: Float32Array;
27
- uv2?: Float32Array;
28
- tangent?: Float32Array;
29
- }
30
-
31
-
32
- var _bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
33
-
34
- var _m1 = new Mat4();
35
- var _offset = new Vec3();
36
- var _box = new Box();
37
- var _boxMorphTargets = new Box();
38
- var _vector = new Vec3();
39
-
40
- /**
41
- * BufferType 几何体,用于独立计算几何体
42
- */
43
- export class BufferGeometry {
44
- name: string;
45
-
46
- boundingBox: Box | undefined;
47
- boundingSphere: Sphere | undefined;
48
-
49
- morphAttributes: any;
50
- morphTargetsRelative: boolean;
51
-
52
- index: BufferAttribute | undefined;
53
- attributes: { [key: string]: BufferAttribute };
54
- groups: { start: number; count: number; materialIndex?: number }[];
55
- drawRange: { start: number; count: number; };
56
-
57
- parameters: any;
58
-
59
- readonly isBufferGeometry: true = true;
60
-
61
- constructor() {
62
-
63
- Object.defineProperty(this, 'id', { value: _bufferGeometryId += 1 });
64
-
65
- this.name = '';
66
-
67
- this.attributes = {};
68
-
69
- this.morphAttributes = {};
70
- this.morphTargetsRelative = false;
71
-
72
- this.groups = [];
73
-
74
- this.drawRange = { start: 0, count: Infinity };
75
- }
76
-
77
- /**
78
- * 转化成BufferArray来计算
79
- * @param geo
80
- */
81
- setFromGeometry(geo: IGeometry | IBufferGeometry) {
82
- this.setAttribute('position', new Float32BufferAttribute(geo.position, 3))
83
- if (geo.uv)
84
- this.setAttribute('uv', new Float32BufferAttribute(geo.uv, 2));
85
-
86
- if (geo.index)
87
- this.setIndex(geo.index)
88
-
89
- return this;
90
- }
91
-
92
- getIndex() {
93
-
94
- return this.index;
95
-
96
- }
97
-
98
- setIndex(index: BufferAttribute | TypedArray | number[]) {
99
- if (Array.isArray(index)) {
100
- this.index = new (vecs.max(index as any) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(index, 1);
101
- } else if (index instanceof BufferAttribute) {
102
- this.index = index;
103
- } else {
104
- this.index = new (vecs.max(index as any) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(index, 1)
105
- }
106
-
107
- }
108
-
109
- getAttribute(name: string) {
110
-
111
- return this.attributes[name];
112
-
113
- }
114
-
115
- setAttribute(name: string, attribute: BufferAttribute) {
116
-
117
- this.attributes[name] = attribute;
118
- return this;
119
-
120
- }
121
-
122
- addAttribute(name: string, attribute: BufferAttribute | TypedArray | Array<number | Vec2 | Vec3 | Vec4>, itemSize: number = 1) {
123
- if (Array.isArray(attribute)) {
124
- if (attribute[0] instanceof Vec2) {
125
- var nums = vecs.verctorToNumbers(attribute);
126
- this.setAttribute(name, new Float32BufferAttribute(nums, 2))
127
- } else if (attribute[0] instanceof Vec3) {
128
- var nums = vecs.verctorToNumbers(attribute);
129
- this.setAttribute(name, new Float32BufferAttribute(nums, 3))
130
- } else if (attribute[0] instanceof Vec4) {
131
- var nums = vecs.verctorToNumbers(attribute);
132
- this.setAttribute(name, new Float32BufferAttribute(nums, 4))
133
- } else if (!isNaN(attribute[0])) {
134
- this.setAttribute(name, new Float32BufferAttribute(attribute, itemSize));
135
- } else {
136
- console.error("类型不存在");
137
- }
138
- }
139
- else if (attribute instanceof BufferAttribute) {
140
- this.attributes[name] = attribute;
141
- } else if (isBufferArray(attribute)) {
142
- this.setAttribute(name, new BufferAttribute(attribute as any, itemSize))
143
- }
144
-
145
- return this;
146
- }
147
-
148
- deleteAttribute(name: string) {
149
-
150
- delete this.attributes[name];
151
- return this;
152
-
153
- }
154
-
155
- addGroup(start: number, count: number, materialIndex?: number) {
156
-
157
- this.groups.push({
158
-
159
- start: start,
160
- count: count,
161
- materialIndex: materialIndex !== undefined ? materialIndex : 0
162
-
163
- });
164
-
165
- }
166
-
167
- clearGroups() {
168
-
169
- this.groups = [];
170
-
171
- }
172
-
173
- setDrawRange(start: number, count: number) {
174
-
175
- this.drawRange.start = start;
176
- this.drawRange.count = count;
177
-
178
- }
179
-
180
- applyMat4(matrix: Mat4) {
181
-
182
- var position = this.attributes.position;
183
-
184
- if (position !== undefined) {
185
-
186
- position.applyMat4(matrix);
187
-
188
- position.needsUpdate = true;
189
-
190
- }
191
-
192
- var normal = this.attributes.normal;
193
-
194
- if (normal !== undefined) {
195
-
196
- var normalMatrix = new Mat3().getNormalMat(matrix);
197
-
198
- normal.applyNormalMat(normalMatrix);
199
-
200
- normal.needsUpdate = true;
201
-
202
- }
203
-
204
- var tangent = this.attributes.tangent;
205
-
206
- if (tangent !== undefined) {
207
-
208
- tangent.transformDirection(matrix);
209
-
210
- tangent.needsUpdate = true;
211
-
212
- }
213
-
214
- if (!this.boundingBox) {
215
-
216
- this.computeBoundingBox();
217
-
218
- }
219
-
220
- if (!this.boundingSphere) {
221
-
222
- this.computeBoundingSphere();
223
-
224
- }
225
-
226
- return this;
227
-
228
- }
229
-
230
- rotateX(angle: number) {
231
-
232
- // rotate geometry around world x-axis
233
-
234
- _m1.makeRotationX(angle);
235
-
236
- this.applyMat4(_m1);
237
-
238
- return this;
239
-
240
- }
241
-
242
- rotateY(angle: number) {
243
-
244
- // rotate geometry around world y-axis
245
-
246
- _m1.makeRotationY(angle);
247
-
248
- this.applyMat4(_m1);
249
-
250
- return this;
251
-
252
- }
253
-
254
- rotateZ(angle: number) {
255
-
256
- // rotate geometry around world z-axis
257
-
258
- _m1.makeRotationZ(angle);
259
-
260
- this.applyMat4(_m1);
261
-
262
- return this;
263
-
264
- }
265
-
266
- translate(x: number, y: number, z: number) {
267
-
268
- // translate geometry
269
-
270
- _m1.makeTranslation(x, y, z);
271
-
272
- this.applyMat4(_m1);
273
-
274
- return this;
275
-
276
- }
277
-
278
- scale(x: number, y: number, z: number) {
279
-
280
- // scale geometry
281
-
282
- _m1.makeScale(x, y, z);
283
-
284
- this.applyMat4(_m1);
285
-
286
- return this;
287
-
288
- }
289
-
290
- lookAt(vector: Vec3) {
291
-
292
- _m1.lookAt(v3(), vector, Vec3.UnitY);
293
-
294
- this.applyMat4(_m1);
295
-
296
- return this;
297
-
298
- }
299
-
300
- center() {
301
-
302
- this.computeBoundingBox();
303
-
304
- this.boundingBox!.getCenter(_offset).negate();
305
-
306
- this.translate(_offset.x, _offset.y, _offset.z);
307
-
308
- return this;
309
-
310
- }
311
-
312
- setFromObject(object: any) {
313
-
314
- // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
315
-
316
- var geometry = object.geometry;
317
-
318
- if (object.isPoints || object.isLine) {
319
-
320
- var positions = new Float32BufferAttribute(geometry.vertices.length * 3, 3);
321
- var colors = new Float32BufferAttribute(geometry.colors.length * 3, 3);
322
-
323
- this.setAttribute('position', positions.copyVec3sArray(geometry.vertices));
324
- this.setAttribute('color', colors.copyColorsArray(geometry.colors));
325
-
326
- if (geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length) {
327
-
328
- var lineDistances = new Float32BufferAttribute(geometry.lineDistances.length, 1);
329
-
330
- this.setAttribute('lineDistance', lineDistances.copyArray(geometry.lineDistances));
331
-
332
- }
333
-
334
- if (geometry.boundingSphere !== null) {
335
-
336
- this.boundingSphere = geometry.boundingSphere.clone();
337
-
338
- }
339
-
340
- if (geometry.boundingBox !== null) {
341
-
342
- this.boundingBox = geometry.boundingBox.clone();
343
-
344
- }
345
-
346
- } else if (object.isMesh) {
347
-
348
- // if (geometry && geometry.isGeometry) {
349
-
350
- // this.fromGeometry(geometry);
351
-
352
- // }
353
-
354
- }
355
-
356
- return this;
357
-
358
- }
359
-
360
- setFromPoints(points: Vec3[]) {
361
-
362
- var position = [];
363
-
364
- for (var i = 0, l = points.length; i < l; i++) {
365
-
366
- var point = points[i];
367
- position.push(point.x, point.y, point.z || 0);
368
-
369
- }
370
-
371
- this.setAttribute('position', new Float32BufferAttribute(position, 3));
372
-
373
- return this;
374
-
375
- }
376
-
377
- updateFromObject(object: any) {
378
-
379
- var geometry = object.geometry;
380
-
381
- if (object.isMesh) {
382
-
383
- var direct = geometry.__directGeometry;
384
-
385
- if (geometry.elementsNeedUpdate === true) {
386
-
387
- direct = undefined;
388
- geometry.elementsNeedUpdate = false;
389
-
390
- }
391
-
392
- // if (direct === undefined) {
393
-
394
- // return this.fromGeometry(geometry);
395
-
396
- // }
397
-
398
- direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
399
- direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
400
- direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
401
- direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
402
- direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
403
-
404
- geometry.verticesNeedUpdate = false;
405
- geometry.normalsNeedUpdate = false;
406
- geometry.colorsNeedUpdate = false;
407
- geometry.uvsNeedUpdate = false;
408
- geometry.groupsNeedUpdate = false;
409
-
410
- geometry = direct;
411
-
412
- }
413
-
414
- var attribute;
415
-
416
- if (geometry.verticesNeedUpdate === true) {
417
-
418
- attribute = this.attributes.position;
419
-
420
- if (attribute !== undefined) {
421
-
422
- attribute.copyVec3sArray(geometry.vertices);
423
- attribute.needsUpdate = true;
424
-
425
- }
426
-
427
- geometry.verticesNeedUpdate = false;
428
-
429
- }
430
-
431
- if (geometry.normalsNeedUpdate === true) {
432
-
433
- attribute = this.attributes.normal;
434
-
435
- if (attribute !== undefined) {
436
-
437
- attribute.copyVec3sArray(geometry.normals);
438
- attribute.needsUpdate = true;
439
-
440
- }
441
-
442
- geometry.normalsNeedUpdate = false;
443
-
444
- }
445
-
446
- if (geometry.colorsNeedUpdate === true) {
447
-
448
- attribute = this.attributes.color;
449
-
450
- if (attribute !== undefined) {
451
-
452
- attribute.copyColorsArray(geometry.colors);
453
- attribute.needsUpdate = true;
454
-
455
- }
456
-
457
- geometry.colorsNeedUpdate = false;
458
-
459
- }
460
-
461
- if (geometry.uvsNeedUpdate) {
462
-
463
- attribute = this.attributes.uv;
464
-
465
- if (attribute !== undefined) {
466
-
467
- attribute.copyVec2sArray(geometry.uvs);
468
- attribute.needsUpdate = true;
469
-
470
- }
471
-
472
- geometry.uvsNeedUpdate = false;
473
-
474
- }
475
-
476
- if (geometry.lineDistancesNeedUpdate) {
477
-
478
- attribute = this.attributes.lineDistance;
479
-
480
- if (attribute !== undefined) {
481
-
482
- attribute.copyArray(geometry.lineDistances);
483
- attribute.needsUpdate = true;
484
-
485
- }
486
-
487
- geometry.lineDistancesNeedUpdate = false;
488
-
489
- }
490
-
491
- if (geometry.groupsNeedUpdate) {
492
-
493
- geometry.computeGroups(object.geometry);
494
- this.groups = geometry.groups;
495
-
496
- geometry.groupsNeedUpdate = false;
497
-
498
- }
499
-
500
- return this;
501
-
502
- }
503
-
504
- // fromGeometry(geometry: any) {
505
-
506
- // geometry.__directGeometry = new DirectGeometry().fromGeometry(geometry);
507
-
508
- // return this.fromDirectGeometry(geometry.__directGeometry);
509
-
510
- // }
511
-
512
- // fromDirectGeometry(geometry) {
513
-
514
- // var positions = new Float32Array(geometry.vertices.length * 3);
515
- // this.setAttribute('position', new BufferAttribute(positions, 3).copyVec3sArray(geometry.vertices));
516
-
517
- // if (geometry.normals.length > 0) {
518
-
519
- // var normals = new Float32Array(geometry.normals.length * 3);
520
- // this.setAttribute('normal', new BufferAttribute(normals, 3).copyVec3sArray(geometry.normals));
521
-
522
- // }
523
-
524
- // if (geometry.colors.length > 0) {
525
-
526
- // var colors = new Float32Array(geometry.colors.length * 3);
527
- // this.setAttribute('color', new BufferAttribute(colors, 3).copyColorsArray(geometry.colors));
528
-
529
- // }
530
-
531
- // if (geometry.uvs.length > 0) {
532
-
533
- // var uvs = new Float32Array(geometry.uvs.length * 2);
534
- // this.setAttribute('uv', new BufferAttribute(uvs, 2).copyVec2sArray(geometry.uvs));
535
-
536
- // }
537
-
538
- // if (geometry.uvs2.length > 0) {
539
-
540
- // var uvs2 = new Float32Array(geometry.uvs2.length * 2);
541
- // this.setAttribute('uv2', new BufferAttribute(uvs2, 2).copyVec2sArray(geometry.uvs2));
542
-
543
- // }
544
-
545
- // // groups
546
-
547
- // this.groups = geometry.groups;
548
-
549
- // // morphs
550
-
551
- // for (var name in geometry.morphTargets) {
552
-
553
- // var array = [];
554
- // var morphTargets = geometry.morphTargets[name];
555
-
556
- // for (var i = 0, l = morphTargets.length; i < l; i++) {
557
-
558
- // var morphTarget = morphTargets[i];
559
-
560
- // var attribute = new Float32BufferAttribute(morphTarget.data.length * 3, 3);
561
- // attribute.name = morphTarget.name;
562
-
563
- // array.push(attribute.copyVec3sArray(morphTarget.data));
564
-
565
- // }
566
-
567
- // this.morphAttributes[name] = array;
568
-
569
- // }
570
-
571
- // // skinning
572
-
573
- // if (geometry.skinIndices.length > 0) {
574
-
575
- // var skinIndices = new Float32BufferAttribute(geometry.skinIndices.length * 4, 4);
576
- // this.setAttribute('skinIndex', skinIndices.copyVec4sArray(geometry.skinIndices));
577
-
578
- // }
579
-
580
- // if (geometry.skinWeights.length > 0) {
581
-
582
- // var skinWeights = new Float32BufferAttribute(geometry.skinWeights.length * 4, 4);
583
- // this.setAttribute('skinWeight', skinWeights.copyVec4sArray(geometry.skinWeights));
584
-
585
- // }
586
-
587
- // //
588
-
589
- // if (geometry.boundingSphere !== null) {
590
-
591
- // this.boundingSphere = geometry.boundingSphere.clone();
592
-
593
- // }
594
-
595
- // if (geometry.boundingBox !== null) {
596
-
597
- // this.boundingBox = geometry.boundingBox.clone();
598
-
599
- // }
600
-
601
- // return this;
602
-
603
- // }
604
-
605
- computeBoundingBox() {
606
-
607
- if (!this.boundingBox) {
608
- this.boundingBox = new Box();
609
- }
610
-
611
- var position = this.attributes.position;
612
- var morphAttributesPosition = this.morphAttributes.position;
613
-
614
- if (position) {
615
-
616
- this.boundingBox!.setFromBufferAttribute(position);
617
-
618
- // process morph attributes if present
619
-
620
- if (morphAttributesPosition) {
621
-
622
- for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
623
-
624
- var morphAttribute = morphAttributesPosition[i];
625
- _box.setFromBufferAttribute(morphAttribute);
626
-
627
- if (this.morphTargetsRelative) {
628
-
629
- _vector.addVecs(this.boundingBox.min, _box.min);
630
- this.boundingBox.expandByPoint(_vector);
631
-
632
- _vector.addVecs(this.boundingBox.max, _box.max);
633
- this.boundingBox.expandByPoint(_vector);
634
-
635
- } else {
636
-
637
- this.boundingBox.expandByPoint(_box.min);
638
- this.boundingBox.expandByPoint(_box.max);
639
-
640
- }
641
-
642
- }
643
-
644
- }
645
-
646
- } else {
647
-
648
- this.boundingBox.makeEmpty();
649
-
650
- }
651
-
652
- if (isNaN(this.boundingBox.min.x) || isNaN(this.boundingBox.min.y) || isNaN(this.boundingBox.min.z)) {
653
-
654
- console.error('THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this);
655
-
656
- }
657
-
658
- }
659
-
660
- computeBoundingSphere() {
661
-
662
- if (!this.boundingSphere) {
663
-
664
- this.boundingSphere = new Sphere();
665
-
666
- }
667
-
668
- var position = this.attributes.position;
669
- var morphAttributesPosition = this.morphAttributes.position;
670
-
671
- if (position) {
672
-
673
- // first, find the center of the bounding sphere
674
-
675
- var center = this.boundingSphere!.center;
676
-
677
- _box.setFromBufferAttribute(position);
678
-
679
- // process morph attributes if present
680
-
681
- if (morphAttributesPosition) {
682
-
683
- for (var i = 0, il: number = morphAttributesPosition.length; i < il; i++) {
684
-
685
- var morphAttribute = morphAttributesPosition[i];
686
- _boxMorphTargets.setFromBufferAttribute(morphAttribute);
687
-
688
- if (this.morphTargetsRelative) {
689
-
690
- _vector.addVecs(_box.min, _boxMorphTargets.min);
691
- _box.expandByPoint(_vector);
692
-
693
- _vector.addVecs(_box.max, _boxMorphTargets.max);
694
- _box.expandByPoint(_vector);
695
-
696
- } else {
697
-
698
- _box.expandByPoint(_boxMorphTargets.min);
699
- _box.expandByPoint(_boxMorphTargets.max);
700
-
701
- }
702
-
703
- }
704
-
705
- }
706
-
707
- _box.getCenter(center);
708
-
709
- // second, try to find a boundingSphere with a radius smaller than the
710
- // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
711
-
712
- var maxRadiusSq = 0;
713
-
714
- for (var i = 0, il: number = position.count; i < il; i++) {
715
-
716
- _vector.fromBufferAttribute(position, i);
717
-
718
- maxRadiusSq = Math.max(maxRadiusSq, center!.distanceToSquared(_vector));
719
-
720
- }
721
-
722
- // process morph attributes if present
723
-
724
- if (morphAttributesPosition) {
725
-
726
- for (var i = 0, il: number = morphAttributesPosition.length; i < il; i++) {
727
-
728
- var morphAttribute = morphAttributesPosition[i];
729
- var morphTargetsRelative = this.morphTargetsRelative;
730
-
731
- for (var j = 0, jl = morphAttribute.count; j < jl; j++) {
732
-
733
- _vector.fromBufferAttribute(morphAttribute, j);
734
-
735
- if (morphTargetsRelative) {
736
-
737
- _offset.fromBufferAttribute(position, j);
738
- _vector.add(_offset);
739
-
740
- }
741
-
742
- maxRadiusSq = Math.max(maxRadiusSq, center!.distanceToSquared(_vector));
743
-
744
- }
745
-
746
- }
747
-
748
- }
749
-
750
- this.boundingSphere!.radius = Math.sqrt(maxRadiusSq);
751
-
752
- if (isNaN(this.boundingSphere!.radius)) {
753
-
754
- console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this);
755
-
756
- }
757
-
758
- }
759
-
760
- }
761
-
762
- computeFaceNormals() {
763
-
764
- // backwards compatibility
765
-
766
- }
767
-
768
- computeVertexNormals() {
769
-
770
- var index = this.index;
771
- var attributes = this.attributes;
772
-
773
- if (attributes.position) {
774
-
775
- var positions = attributes.position.array;
776
-
777
- if (attributes.normal === undefined) {
778
-
779
- this.setAttribute('normal', new BufferAttribute(new Float32Array(positions.length), 3));
780
-
781
- } else {
782
-
783
- // reset existing normals to zero
784
-
785
- var array = attributes.normal.array;
786
-
787
- for (var i = 0, il = array.length; i < il; i++) {
788
-
789
- array[i] = 0;
790
-
791
- }
792
-
793
- }
794
-
795
- var normals = attributes.normal.array;
796
-
797
- var vA, vB, vC;
798
- var pA = new Vec3(), pB = new Vec3(), pC = new Vec3();
799
- var cb = new Vec3(), ab = new Vec3();
800
-
801
- // indexed elements
802
-
803
- if (index) {
804
-
805
- var indices = index.array;
806
-
807
- for (var i = 0, il = index.count; i < il; i += 3) {
808
-
809
- vA = indices[i + 0] * 3;
810
- vB = indices[i + 1] * 3;
811
- vC = indices[i + 2] * 3;
812
-
813
- pA.fromArray(positions, vA);
814
- pB.fromArray(positions, vB);
815
- pC.fromArray(positions, vC);
816
-
817
- cb.subVecs(pC, pB);
818
- ab.subVecs(pA, pB);
819
- cb.cross(ab);
820
-
821
- normals[vA] += cb.x;
822
- normals[vA + 1] += cb.y;
823
- normals[vA + 2] += cb.z;
824
-
825
- normals[vB] += cb.x;
826
- normals[vB + 1] += cb.y;
827
- normals[vB + 2] += cb.z;
828
-
829
- normals[vC] += cb.x;
830
- normals[vC + 1] += cb.y;
831
- normals[vC + 2] += cb.z;
832
-
833
- }
834
-
835
- } else {
836
-
837
- // non-indexed elements (unconnected triangle soup)
838
-
839
- for (var i = 0, il = positions.length; i < il; i += 9) {
840
-
841
- pA.fromArray(positions, i);
842
- pB.fromArray(positions, i + 3);
843
- pC.fromArray(positions, i + 6);
844
-
845
- cb.subVecs(pC, pB);
846
- ab.subVecs(pA, pB);
847
- cb.cross(ab);
848
-
849
- normals[i] = cb.x;
850
- normals[i + 1] = cb.y;
851
- normals[i + 2] = cb.z;
852
-
853
- normals[i + 3] = cb.x;
854
- normals[i + 4] = cb.y;
855
- normals[i + 5] = cb.z;
856
-
857
- normals[i + 6] = cb.x;
858
- normals[i + 7] = cb.y;
859
- normals[i + 8] = cb.z;
860
-
861
- }
862
-
863
- }
864
-
865
- this.normalizeNormals();
866
-
867
- attributes.normal.needsUpdate = true;
868
-
869
- }
870
-
871
- }
872
-
873
- merge(geometry: BufferGeometry, offset: number) {
874
-
875
- if (!(geometry && geometry.isBufferGeometry)) {
876
-
877
- console.error('THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry);
878
- return;
879
-
880
- }
881
-
882
- if (offset === undefined) {
883
-
884
- offset = 0;
885
-
886
- console.warn(
887
- 'THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. '
888
- + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.'
889
- );
890
-
891
- }
892
-
893
- var attributes = this.attributes;
894
-
895
- for (var key in attributes) {
896
-
897
- if (geometry.attributes[key] === undefined) continue;
898
-
899
- var attribute1 = attributes[key];
900
- var attributeArray1 = attribute1.array;
901
-
902
- var attribute2 = geometry.attributes[key];
903
- var attributeArray2 = attribute2.array;
904
-
905
- var attributeOffset = attribute2.itemSize * offset;
906
- var length = Math.min(attributeArray2.length, attributeArray1.length - attributeOffset);
907
-
908
- for (var i = 0, j = attributeOffset; i < length; i++, j++) {
909
-
910
- attributeArray1[j] = attributeArray2[i];
911
-
912
- }
913
-
914
- }
915
-
916
- return this;
917
-
918
- }
919
-
920
- normalizeNormals() {
921
-
922
- var normals = this.attributes.normal;
923
-
924
- for (var i = 0, il = normals.count; i < il; i++) {
925
-
926
- _vector.x = normals.getX(i);
927
- _vector.y = normals.getY(i);
928
- _vector.z = normals.getZ(i);
929
-
930
- _vector.normalize();
931
-
932
- normals.setXYZ(i, _vector.x, _vector.y, _vector.z);
933
-
934
- }
935
-
936
- }
937
-
938
- toFlat() {
939
- var indices = this.index!.array;
940
- var attributes = this.attributes;
941
- var geometry2 = new BufferGeometry();
942
- function convertBufferAttribute(attribute: BufferAttribute, indices: ArrayLike<number>) {
943
-
944
- var array = attribute.array;
945
- var itemSize = attribute.itemSize;
946
-
947
- var array2 = new (array as any).constructor(indices.length * itemSize);
948
-
949
- var index = 0, index2 = 0;
950
-
951
- for (var i = 0, l = indices.length; i < l; i++) {
952
-
953
- index = indices[i] * itemSize;
954
-
955
- for (var j = 0; j < itemSize; j++) {
956
-
957
- array2[index2++] = array[index++];
958
-
959
- }
960
-
961
- }
962
-
963
- return new BufferAttribute(array2, itemSize);
964
-
965
- }
966
-
967
- for (var name in attributes) {
968
-
969
- var attribute = attributes[name];
970
-
971
- var newAttribute = convertBufferAttribute(attribute, indices);
972
-
973
- geometry2.setAttribute(name, newAttribute);
974
-
975
- }
976
-
977
- const indices2 = indices.map((v: number, i: number) => i);
978
-
979
- geometry2.setIndex(indices2);
980
-
981
- return geometry2;
982
- }
983
-
984
- toNonIndexed() {
985
-
986
- function convertBufferAttribute(attribute: BufferAttribute, indices: ArrayLike<number>) {
987
-
988
- var array = attribute.array;
989
- var itemSize = attribute.itemSize;
990
-
991
- var array2 = new (array as any).constructor(indices.length * itemSize);
992
-
993
- var index = 0, index2 = 0;
994
-
995
- for (var i = 0, l = indices.length; i < l; i++) {
996
-
997
- index = indices[i] * itemSize;
998
-
999
- for (var j = 0; j < itemSize; j++) {
1000
-
1001
- array2[index2++] = array[index++];
1002
-
1003
- }
1004
-
1005
- }
1006
-
1007
- return new BufferAttribute(array2, itemSize);
1008
-
1009
- }
1010
-
1011
- //
1012
-
1013
- if (this.index === undefined) {
1014
-
1015
- console.warn('THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.');
1016
- return this;
1017
-
1018
- }
1019
-
1020
- var geometry2 = new BufferGeometry();
1021
-
1022
- var indices = this.index!.array;
1023
- var attributes = this.attributes;
1024
-
1025
- // attributes
1026
-
1027
- for (var name in attributes) {
1028
-
1029
- var attribute = attributes[name];
1030
-
1031
- var newAttribute = convertBufferAttribute(attribute, indices);
1032
-
1033
- geometry2.setAttribute(name, newAttribute);
1034
-
1035
- }
1036
-
1037
- // morph attributes
1038
-
1039
- var morphAttributes = this.morphAttributes;
1040
-
1041
- for (name in morphAttributes) {
1042
-
1043
- var morphArray = [];
1044
- var morphAttribute = morphAttributes[name]; // morphAttribute: array of Float32BufferAttributes
1045
-
1046
- for (var i = 0, il = morphAttribute.length; i < il; i++) {
1047
-
1048
- var attribute: BufferAttribute = morphAttribute[i];
1049
-
1050
- var newAttribute = convertBufferAttribute(attribute, indices);
1051
-
1052
- morphArray.push(newAttribute);
1053
-
1054
- }
1055
-
1056
- geometry2.morphAttributes[name] = morphArray;
1057
-
1058
- }
1059
-
1060
- geometry2.morphTargetsRelative = this.morphTargetsRelative;
1061
-
1062
- // groups
1063
-
1064
- var groups = this.groups;
1065
-
1066
- for (var i = 0, l = groups.length; i < l; i++) {
1067
-
1068
- var group = groups[i];
1069
- geometry2.addGroup(group.start, group.count, group.materialIndex);
1070
-
1071
- }
1072
-
1073
- return geometry2;
1074
-
1075
- }
1076
-
1077
- toJSON() {
1078
-
1079
- var data: any = {
1080
- metadata: {
1081
- version: 4.5,
1082
- type: 'BufferGeometry',
1083
- generator: 'BufferGeometry.toJSON'
1084
- }
1085
- };
1086
-
1087
- // standard BufferGeometry serialization
1088
-
1089
- // data.uuid = this.uuid;
1090
- // data.type = this.type;
1091
- if (this.name !== '') data.name = this.name;
1092
- if (Object.keys(this.userData).length > 0) data.userData = this.userData;
1093
-
1094
- if (this.parameters !== undefined) {
1095
-
1096
- var parameters = this.parameters;
1097
-
1098
- for (var key in parameters) {
1099
-
1100
- if (parameters[key] !== undefined) data[key] = parameters[key];
1101
-
1102
- }
1103
-
1104
- return data;
1105
-
1106
- }
1107
-
1108
- data.data = { attributes: {} };
1109
-
1110
- var index = this.index;
1111
-
1112
- if (index) {
1113
-
1114
- data.data.index = {
1115
- type: index.array.constructor.name,
1116
- array: Array.prototype.slice.call(index.array)
1117
- };
1118
-
1119
- }
1120
-
1121
- var attributes = this.attributes;
1122
-
1123
- for (var key in attributes) {
1124
-
1125
- var attribute = attributes[key];
1126
-
1127
- var attributeData: any = attribute.toJSON();
1128
-
1129
- if (attribute.name !== '') attributeData.name = attribute.name;
1130
-
1131
- data.data.attributes[key] = attributeData;
1132
-
1133
- }
1134
-
1135
- var morphAttributes: any = {};
1136
- var hasMorphAttributes = false;
1137
-
1138
- for (var key in this.morphAttributes) {
1139
-
1140
- var attributeArray = this.morphAttributes[key];
1141
-
1142
- var array = [];
1143
-
1144
- for (var i = 0, il = attributeArray.length; i < il; i++) {
1145
-
1146
- var attribute: BufferAttribute = attributeArray[i];
1147
-
1148
- var attributeData: any = attribute.toJSON();
1149
-
1150
- if (attribute.name !== '') attributeData.name = attribute.name;
1151
-
1152
- array.push(attributeData);
1153
-
1154
- }
1155
-
1156
- if (array.length > 0) {
1157
-
1158
- morphAttributes[key] = array;
1159
-
1160
- hasMorphAttributes = true;
1161
-
1162
- }
1163
-
1164
- }
1165
-
1166
- if (hasMorphAttributes) {
1167
-
1168
- data.data.morphAttributes = morphAttributes;
1169
- data.data.morphTargetsRelative = this.morphTargetsRelative;
1170
-
1171
- }
1172
-
1173
- var groups = this.groups;
1174
-
1175
- if (groups.length > 0) {
1176
-
1177
- data.data.groups = JSON.parse(JSON.stringify(groups));
1178
-
1179
- }
1180
-
1181
- var boundingSphere = this.boundingSphere;
1182
-
1183
- if (boundingSphere) {
1184
-
1185
- data.data.boundingSphere = {
1186
- center: boundingSphere.center.toArray(),
1187
- radius: boundingSphere.radius
1188
- };
1189
-
1190
- }
1191
-
1192
- return data;
1193
-
1194
- }
1195
- userData(userData: any) {
1196
- throw new Error("Method not implemented.");
1197
- }
1198
-
1199
- clone() {
1200
-
1201
- /*
1202
- // Handle primitives
1203
-
1204
- var parameters = this.parameters;
1205
-
1206
- if ( parameters !== undefined ) {
1207
-
1208
- var values = [];
1209
-
1210
- for ( var key in parameters ) {
1211
-
1212
- values.push( parameters[ key ] );
1213
-
1214
- }
1215
-
1216
- var geometry = Object.create( this.constructor.prototype );
1217
- this.constructor.apply( geometry, values );
1218
- return geometry;
1219
-
1220
- }
1221
-
1222
- return new this.constructor().copy( this );
1223
- */
1224
-
1225
- return new BufferGeometry().copy(this);
1226
-
1227
- }
1228
-
1229
- copy(source: BufferGeometry) {
1230
-
1231
- var name, i, l;
1232
-
1233
- // reset
1234
-
1235
- this.attributes = {};
1236
- this.morphAttributes = {};
1237
- this.groups = [];
1238
-
1239
- // name
1240
-
1241
- this.name = source.name;
1242
-
1243
- // index
1244
-
1245
- var index = source.index;
1246
-
1247
- if (index) {
1248
-
1249
- this.setIndex(index.clone());
1250
-
1251
- }
1252
-
1253
- // attributes
1254
-
1255
- var attributes = source.attributes;
1256
-
1257
- for (name in attributes) {
1258
-
1259
- var attribute = attributes[name];
1260
- this.setAttribute(name, attribute.clone());
1261
-
1262
- }
1263
-
1264
- // morph attributes
1265
-
1266
- var morphAttributes = source.morphAttributes;
1267
-
1268
- for (name in morphAttributes) {
1269
-
1270
- var array = [];
1271
- var morphAttribute = morphAttributes[name]; // morphAttribute: array of Float32BufferAttributes
1272
-
1273
- for (i = 0, l = morphAttribute.length; i < l; i++) {
1274
-
1275
- array.push(morphAttribute[i].clone());
1276
-
1277
- }
1278
-
1279
- this.morphAttributes[name] = array;
1280
-
1281
- }
1282
-
1283
- this.morphTargetsRelative = source.morphTargetsRelative;
1284
-
1285
- // groups
1286
-
1287
- var groups = source.groups;
1288
-
1289
- for (i = 0, l = groups.length; i < l; i++) {
1290
-
1291
- var group = groups[i];
1292
- this.addGroup(group.start, group.count, group.materialIndex);
1293
-
1294
- }
1295
-
1296
- // bounding box
1297
-
1298
- var boundingBox = source.boundingBox;
1299
-
1300
- if (boundingBox) {
1301
-
1302
- this.boundingBox = boundingBox.clone();
1303
-
1304
- }
1305
-
1306
- // bounding sphere
1307
-
1308
- var boundingSphere = source.boundingSphere;
1309
-
1310
- if (boundingSphere) {
1311
-
1312
- this.boundingSphere = boundingSphere.clone();
1313
-
1314
- }
1315
-
1316
- // draw range
1317
-
1318
- this.drawRange.start = source.drawRange.start;
1319
- this.drawRange.count = source.drawRange.count;
1320
-
1321
- // user data
1322
-
1323
- this.userData = source.userData;
1324
-
1325
- return this;
1326
-
1327
- }
1328
-
1329
- }