@realsee/five 5.0.0-alpha.18 → 5.0.0-alpha.181

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 (252) hide show
  1. package/README.md +21 -11
  2. package/docs/.nojekyll +1 -0
  3. package/docs/assets/highlight.css +134 -0
  4. package/docs/assets/icons.css +1043 -0
  5. package/docs/assets/{images/icons.png → icons.png} +0 -0
  6. package/docs/assets/{images/icons@2x.png → icons@2x.png} +0 -0
  7. package/docs/assets/main.js +52 -0
  8. package/docs/assets/search.js +1 -0
  9. package/docs/assets/style.css +1414 -0
  10. package/docs/assets/{images/widgets.png → widgets.png} +0 -0
  11. package/docs/assets/{images/widgets@2x.png → widgets@2x.png} +0 -0
  12. package/docs/classes/five.AnimationFrameLoop.html +15 -0
  13. package/docs/classes/five.BVH.html +10 -0
  14. package/docs/classes/five.BVHIntersect.html +1 -0
  15. package/docs/classes/five.BVHNode.html +7 -0
  16. package/docs/classes/five.BVHVector3.html +1 -0
  17. package/docs/classes/five.Camera.html +11 -0
  18. package/docs/classes/five.Clipper.html +1 -0
  19. package/docs/classes/five.Five.html +328 -0
  20. package/docs/classes/five.InternalWebGLRenderer.html +1 -0
  21. package/docs/classes/five.IntersectMesh.html +1 -0
  22. package/docs/classes/five.Model.html +89 -0
  23. package/docs/classes/five.NetworkSubscribe.html +50 -0
  24. package/docs/classes/five.PBMContainer.html +17 -0
  25. package/docs/classes/five.PBMGroup.html +19 -0
  26. package/docs/classes/five.PBMMaterial.html +27 -0
  27. package/docs/classes/five.PBMMesh.html +7 -0
  28. package/docs/classes/five.PanoCircleMesh.html +7 -0
  29. package/docs/classes/five.PanoCircleMeshCustom.html +7 -0
  30. package/docs/classes/five.PanoCircleMeshSolid.html +7 -0
  31. package/docs/classes/five.Scene.html +3 -0
  32. package/docs/classes/five.Subscribe.html +56 -0
  33. package/docs/classes/five.TextureLoader.html +1 -0
  34. package/docs/classes/five.Tile3D.html +34 -0
  35. package/docs/classes/five.Tile3DModel.html +15 -0
  36. package/docs/classes/five.TileBoundingSphere.html +1 -0
  37. package/docs/classes/five.TileCacheNode.html +1 -0
  38. package/docs/classes/five.TileCubeTextureTarget.html +1 -0
  39. package/docs/classes/five.TileCullingVolume.html +1 -0
  40. package/docs/classes/five.TileOrientedBoundingBox.html +1 -0
  41. package/docs/classes/five.TileRequestScheduler.html +16 -0
  42. package/docs/classes/five.Tileset3D.html +11 -0
  43. package/docs/classes/five.Tileset3DTraverser.html +1 -0
  44. package/docs/classes/five.TilesetCache.html +1 -0
  45. package/docs/classes/five.Work.html +32 -0
  46. package/docs/classes/five.XRButton.html +1 -0
  47. package/docs/classes/gltf_loader.DDSLoader.html +1 -0
  48. package/docs/classes/gltf_loader.DRACOLoader.html +1 -0
  49. package/docs/classes/gltf_loader.GLTFLoader.html +17 -0
  50. package/docs/classes/gltf_loader.GLTFObject.html +7 -0
  51. package/docs/classes/gltf_loader.GLTFParser.html +1 -0
  52. package/docs/classes/gltf_loader.THREEGLTFLoader.html +1 -0
  53. package/docs/classes/line.Line.html +1 -0
  54. package/docs/classes/line.LineGeometry.html +1 -0
  55. package/docs/classes/line.LineMaterial.html +1 -0
  56. package/docs/classes/line.LineSegmentsGeometry.html +1 -0
  57. package/docs/classes/line.THREE_Line2.html +1 -0
  58. package/docs/classes/line.THREE_LineSegments2.html +1 -0
  59. package/docs/classes/react.Store.html +29 -0
  60. package/docs/classes/server.BVH.html +10 -0
  61. package/docs/classes/server.BVHIntersect.html +1 -0
  62. package/docs/classes/server.BVHNode.html +7 -0
  63. package/docs/classes/server.BVHVector3.html +1 -0
  64. package/docs/classes/server.Model.html +70 -0
  65. package/docs/classes/server.PBMContainer.html +7 -0
  66. package/docs/classes/server.PBMGroup.html +9 -0
  67. package/docs/classes/server.PBMMesh.html +7 -0
  68. package/docs/classes/sticker.Sticker.html +32 -0
  69. package/docs/classes/vfx.Airflow.html +1 -0
  70. package/docs/classes/vfx.Flame.html +1 -0
  71. package/docs/classes/vfx.Particle.html +89 -0
  72. package/docs/classes/vfx.SpotLight.html +1 -0
  73. package/docs/index.html +166 -434
  74. package/docs/interfaces/five.AddableObject.html +9 -0
  75. package/docs/interfaces/five.AnimationFrame.html +1 -0
  76. package/docs/interfaces/five.CameraPose.html +1 -0
  77. package/docs/interfaces/five.ClipperParameter.html +1 -0
  78. package/docs/interfaces/five.DepthPanoramaControllerCustomInitArgs.html +28 -0
  79. package/docs/interfaces/five.EventCallback.html +400 -0
  80. package/docs/interfaces/five.FiveInitArgs.html +109 -0
  81. package/docs/interfaces/five.FloorplanControllerCustomInitArgs.html +17 -0
  82. package/docs/interfaces/five.ImageOptions.html +18 -0
  83. package/docs/interfaces/five.ImageURLMappings.html +1 -0
  84. package/docs/interfaces/five.ImageURLOptions.html +15 -0
  85. package/docs/interfaces/five.IntersectMeshInterface.html +3 -0
  86. package/docs/interfaces/five.Intersection.html +7 -0
  87. package/docs/interfaces/five.MapviewControllerCustomInitArgs.html +15 -0
  88. package/docs/interfaces/five.ModelControllerCustomInitArgs.html +20 -0
  89. package/docs/interfaces/five.ModelEventCallback.html +22 -0
  90. package/docs/interfaces/five.MotionKeyframe.html +1 -0
  91. package/docs/interfaces/five.MovePanoOptions.html +42 -0
  92. package/docs/interfaces/five.NetworkOptions.html +9 -0
  93. package/docs/interfaces/five.PBMPanoPicture.html +7 -0
  94. package/docs/interfaces/five.PBMParameters.html +27 -0
  95. package/docs/interfaces/five.PanoCircleMeshCustomOptions.html +1 -0
  96. package/docs/interfaces/five.PanoCircleMeshInterface.html +19 -0
  97. package/docs/interfaces/five.PanoCircleMeshOptions.html +1 -0
  98. package/docs/interfaces/five.PanoCircleMeshSolidOptions.html +1 -0
  99. package/docs/interfaces/five.PanoramaControllerCustomInitArgs.html +35 -0
  100. package/docs/interfaces/five.PanoramaLikeControllerCustomInitArgs.html +20 -0
  101. package/docs/interfaces/five.Pose.html +37 -0
  102. package/docs/interfaces/five.Scissor.html +14 -0
  103. package/docs/interfaces/five.State.html +21 -0
  104. package/docs/interfaces/five.SubscribeMixinType.emit.html +1 -0
  105. package/docs/interfaces/five.SubscribeMixinType.hasListener.html +1 -0
  106. package/docs/interfaces/five.SubscribeMixinType.off.html +1 -0
  107. package/docs/interfaces/five.SubscribeMixinType.on.html +1 -0
  108. package/docs/interfaces/five.SubscribeMixinType.once.html +1 -0
  109. package/docs/interfaces/five.TextureOptions.html +20 -0
  110. package/docs/interfaces/five.Tile3DModelLoaderOptions.html +3 -0
  111. package/docs/interfaces/five.TileBoundingVolume.html +19 -0
  112. package/docs/interfaces/five.TileContent.html +1 -0
  113. package/docs/interfaces/five.TileCubeNode.html +1 -0
  114. package/docs/interfaces/five.TileCubeTree.html +1 -0
  115. package/docs/interfaces/five.Tileset3dOptions.html +1 -0
  116. package/docs/interfaces/five.TilesetJSON.html +1 -0
  117. package/docs/interfaces/five.TilesetJSONNode.html +1 -0
  118. package/docs/interfaces/five.TopviewControllerCustomInitArgs.html +9 -0
  119. package/docs/interfaces/five.VRPanoramaControllerCustomInitArgs.html +31 -0
  120. package/docs/interfaces/five.WebXRSelectParams.html +1 -0
  121. package/docs/interfaces/five.WorkCubeImage.html +13 -0
  122. package/docs/interfaces/five.WorkImage.html +21 -0
  123. package/docs/interfaces/five.WorkInitial.html +13 -0
  124. package/docs/interfaces/five.WorkModel.html +11 -0
  125. package/docs/interfaces/five.WorkModelTiles.html +3 -0
  126. package/docs/interfaces/five.WorkObserver.html +25 -0
  127. package/docs/interfaces/five.WorkTile.html +1 -0
  128. package/docs/interfaces/five.WorkVideo.html +9 -0
  129. package/docs/interfaces/five.XRPanoramaControllerCustomInitArgs.html +31 -0
  130. package/docs/interfaces/gltf_loader.DDS.html +1 -0
  131. package/docs/interfaces/gltf_loader.GLTF.html +7 -0
  132. package/docs/interfaces/gltf_loader.GLTFReference.html +1 -0
  133. package/docs/interfaces/gltf_loader.THREEGLTF.html +1 -0
  134. package/docs/interfaces/react.FiveActionReactCallbacks.html +52 -0
  135. package/docs/interfaces/react.FiveInjectionTypes.html +181 -0
  136. package/docs/interfaces/react.PropTypeOfFiveFeatures.html +1 -0
  137. package/docs/interfaces/server.Intersection.html +7 -0
  138. package/docs/interfaces/server.ModelEventCallback.html +18 -0
  139. package/docs/interfaces/sticker.IntersectionLike.html +8 -0
  140. package/docs/interfaces/vfx.ParticleArgs.html +75 -0
  141. package/docs/interfaces/vfx.ParticleTweenKeyframe.html +1 -0
  142. package/docs/interfaces/vue.FiveActionVueCallbacks.html +60 -0
  143. package/docs/modules/five.SubscribeMixinType.html +1 -0
  144. package/docs/modules/five.html +479 -3002
  145. package/docs/modules/gltf_loader.html +1 -155
  146. package/docs/modules/line.html +1 -202
  147. package/docs/modules/react.html +130 -1507
  148. package/docs/modules/server.html +18 -526
  149. package/docs/modules/sticker.html +1 -151
  150. package/docs/modules/vfx.html +1 -0
  151. package/docs/modules/vue.html +115 -0
  152. package/docs/modules.html +1 -136
  153. package/exporters/staticify.js +210 -0
  154. package/five/index.d.ts +1416 -285
  155. package/five/index.js +362 -1
  156. package/gltf-loader/index.d.ts +90 -5
  157. package/gltf-loader/index.js +260 -1
  158. package/line/index.d.ts +15 -2
  159. package/line/index.js +260 -1
  160. package/package.json +12 -15
  161. package/react/index.d.ts +73 -72
  162. package/react/index.js +260 -1
  163. package/resource/{basis_transcoder.js → basis/basis_transcoder.js} +0 -0
  164. package/resource/{basis_transcoder.wasm → basis/basis_transcoder.wasm} +0 -0
  165. package/resource/{draco_decoder.js → gltf/draco_decoder.js} +0 -0
  166. package/resource/{draco_decoder.wasm → gltf/draco_decoder.wasm} +0 -0
  167. package/resource/{draco_wasm_wrapper.js → gltf/draco_wasm_wrapper.js} +0 -0
  168. package/scripts/five-staticify.js +26 -0
  169. package/server/index.d.ts +219 -27
  170. package/server/index.js +357 -1
  171. package/sticker/index.d.ts +2 -1
  172. package/sticker/index.js +260 -1
  173. package/templates/quick-start/README.md +1 -1
  174. package/templates/quick-start/package.json +1 -1
  175. package/umd/five-gltf-loader.js +1 -2
  176. package/umd/five-line.js +1 -2
  177. package/umd/five-react.js +1 -2
  178. package/umd/five-sticker.js +1 -2
  179. package/umd/five-vfx.js +1 -0
  180. package/umd/five-vue.js +1 -0
  181. package/umd/five.js +1 -1
  182. package/umd/five.js.LICENSE.txt +58 -118
  183. package/vfx/index.d.ts +264 -0
  184. package/vfx/index.js +260 -0
  185. package/vue/index.d.ts +441 -0
  186. package/vue/index.js +260 -0
  187. package/docs/assets/css/main.css +0 -2660
  188. package/docs/assets/js/main.js +0 -248
  189. package/docs/assets/js/search.js +0 -1
  190. package/docs/classes/five.camera.html +0 -323
  191. package/docs/classes/five.five-1.html +0 -2670
  192. package/docs/classes/five.hashcubetexture.html +0 -252
  193. package/docs/classes/five.internalwebglrenderer.html +0 -212
  194. package/docs/classes/five.model.html +0 -982
  195. package/docs/classes/five.pbmgroup.html +0 -427
  196. package/docs/classes/five.pbmmaterial.html +0 -533
  197. package/docs/classes/five.pbmmesh.html +0 -254
  198. package/docs/classes/five.scene.html +0 -263
  199. package/docs/classes/five.subscribe.html +0 -569
  200. package/docs/classes/gltf_loader.gltfloader.html +0 -412
  201. package/docs/classes/gltf_loader.gltfobject.html +0 -287
  202. package/docs/classes/line.line-1.html +0 -381
  203. package/docs/classes/line.linegeometry.html +0 -524
  204. package/docs/classes/line.linematerial.html +0 -300
  205. package/docs/classes/line.linesegmentsgeometry.html +0 -471
  206. package/docs/classes/react.store.html +0 -605
  207. package/docs/classes/server.model.html +0 -823
  208. package/docs/classes/server.pbmgroup.html +0 -366
  209. package/docs/classes/server.pbmmesh.html +0 -335
  210. package/docs/classes/sticker.sticker-1.html +0 -465
  211. package/docs/interfaces/five.addableobject.html +0 -234
  212. package/docs/interfaces/five.depthpanoramacontrollercustominitargs.html +0 -420
  213. package/docs/interfaces/five.eventcallback.html +0 -2548
  214. package/docs/interfaces/five.fiveinitargs.html +0 -707
  215. package/docs/interfaces/five.floorplancontrollercustominitargs.html +0 -295
  216. package/docs/interfaces/five.imageoptions.html +0 -332
  217. package/docs/interfaces/five.intersection.html +0 -227
  218. package/docs/interfaces/five.intersectmeshinterface.html +0 -188
  219. package/docs/interfaces/five.modelcontrollercustominitargs.html +0 -366
  220. package/docs/interfaces/five.modeleventcallback.html +0 -367
  221. package/docs/interfaces/five.movepanooptions.html +0 -469
  222. package/docs/interfaces/five.panocirclemeshinterface.html +0 -361
  223. package/docs/interfaces/five.panoramacontrollercustominitargs.html +0 -464
  224. package/docs/interfaces/five.panoramalikecontrollercustominitargs.html +0 -364
  225. package/docs/interfaces/five.pbmparameters.html +0 -474
  226. package/docs/interfaces/five.pose.html +0 -270
  227. package/docs/interfaces/five.scissor.html +0 -252
  228. package/docs/interfaces/five.state.html +0 -300
  229. package/docs/interfaces/five.subscribemixintype.emit.html +0 -180
  230. package/docs/interfaces/five.subscribemixintype.haslistener.html +0 -171
  231. package/docs/interfaces/five.subscribemixintype.off.html +0 -198
  232. package/docs/interfaces/five.subscribemixintype.on.html +0 -213
  233. package/docs/interfaces/five.subscribemixintype.once.html +0 -210
  234. package/docs/interfaces/five.topviewcontrollercustominitargs.html +0 -226
  235. package/docs/interfaces/five.vrpanoramacontrollercustominitargs.html +0 -452
  236. package/docs/interfaces/gltf_loader.gltf.html +0 -304
  237. package/docs/interfaces/react.fiveactionreactcallbacks.html +0 -580
  238. package/docs/interfaces/react.fiveinjectiontypes.html +0 -1625
  239. package/docs/interfaces/react.injectfivetoprops.html +0 -280
  240. package/docs/interfaces/server.intersection.html +0 -308
  241. package/docs/interfaces/server.modeleventcallback.html +0 -409
  242. package/docs/interfaces/sticker.intersectionlike.html +0 -223
  243. package/docs/modules/five.subscribemixintype.html +0 -143
  244. package/scripts/export-five-resource/chfs.exe +0 -0
  245. package/scripts/export-five-resource/fileify.js +0 -192
  246. package/scripts/export-five-resource/format-work.js +0 -71
  247. package/scripts/export-five-resource/staticify.js +0 -327
  248. package/scripts/transcode-model/BufferGeometryUtils.js +0 -832
  249. package/scripts/transcode-model/LoaderSupport.js +0 -1545
  250. package/scripts/transcode-model/MTLLoader.js +0 -602
  251. package/scripts/transcode-model/OBJLoader2.js +0 -1470
  252. package/scripts/transcode-model/obj2pbm.js +0 -65
@@ -1,832 +0,0 @@
1
- var THREE = require('three');
2
-
3
- ( function () {
4
-
5
- class BufferGeometryUtils {
6
-
7
- static computeTangents( geometry ) {
8
-
9
- geometry.computeTangents();
10
- console.warn( 'THREE.BufferGeometryUtils: .computeTangents() has been removed. Use THREE.BufferGeometry.computeTangents() instead.' );
11
-
12
- }
13
- /**
14
- * @param {Array<BufferGeometry>} geometries
15
- * @param {Boolean} useGroups
16
- * @return {BufferGeometry}
17
- */
18
-
19
-
20
- static mergeBufferGeometries( geometries, useGroups = false ) {
21
-
22
- const isIndexed = geometries[ 0 ].index !== null;
23
- const attributesUsed = new Set( Object.keys( geometries[ 0 ].attributes ) );
24
- const morphAttributesUsed = new Set( Object.keys( geometries[ 0 ].morphAttributes ) );
25
- const attributes = {};
26
- const morphAttributes = {};
27
- const morphTargetsRelative = geometries[ 0 ].morphTargetsRelative;
28
- const mergedGeometry = new THREE.BufferGeometry();
29
- let offset = 0;
30
-
31
- for ( let i = 0; i < geometries.length; ++ i ) {
32
-
33
- const geometry = geometries[ i ];
34
- let attributesCount = 0; // ensure that all geometries are indexed, or none
35
-
36
- if ( isIndexed !== ( geometry.index !== null ) ) {
37
-
38
- console.error( 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index ' + i + '. All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.' );
39
- return null;
40
-
41
- } // gather attributes, exit early if they're different
42
-
43
-
44
- for ( const name in geometry.attributes ) {
45
-
46
- if ( ! attributesUsed.has( name ) ) {
47
-
48
- console.error( 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index ' + i + '. All geometries must have compatible attributes; make sure "' + name + '" attribute exists among all geometries, or in none of them.' );
49
- return null;
50
-
51
- }
52
-
53
- if ( attributes[ name ] === undefined ) attributes[ name ] = [];
54
- attributes[ name ].push( geometry.attributes[ name ] );
55
- attributesCount ++;
56
-
57
- } // ensure geometries have the same number of attributes
58
-
59
-
60
- if ( attributesCount !== attributesUsed.size ) {
61
-
62
- console.error( 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index ' + i + '. Make sure all geometries have the same number of attributes.' );
63
- return null;
64
-
65
- } // gather morph attributes, exit early if they're different
66
-
67
-
68
- if ( morphTargetsRelative !== geometry.morphTargetsRelative ) {
69
-
70
- console.error( 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index ' + i + '. .morphTargetsRelative must be consistent throughout all geometries.' );
71
- return null;
72
-
73
- }
74
-
75
- for ( const name in geometry.morphAttributes ) {
76
-
77
- if ( ! morphAttributesUsed.has( name ) ) {
78
-
79
- console.error( 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index ' + i + '. .morphAttributes must be consistent throughout all geometries.' );
80
- return null;
81
-
82
- }
83
-
84
- if ( morphAttributes[ name ] === undefined ) morphAttributes[ name ] = [];
85
- morphAttributes[ name ].push( geometry.morphAttributes[ name ] );
86
-
87
- } // gather .userData
88
-
89
-
90
- mergedGeometry.userData.mergedUserData = mergedGeometry.userData.mergedUserData || [];
91
- mergedGeometry.userData.mergedUserData.push( geometry.userData );
92
-
93
- if ( useGroups ) {
94
-
95
- let count;
96
-
97
- if ( isIndexed ) {
98
-
99
- count = geometry.index.count;
100
-
101
- } else if ( geometry.attributes.position !== undefined ) {
102
-
103
- count = geometry.attributes.position.count;
104
-
105
- } else {
106
-
107
- console.error( 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index ' + i + '. The geometry must have either an index or a position attribute' );
108
- return null;
109
-
110
- }
111
-
112
- mergedGeometry.addGroup( offset, count, i );
113
- offset += count;
114
-
115
- }
116
-
117
- } // merge indices
118
-
119
-
120
- if ( isIndexed ) {
121
-
122
- let indexOffset = 0;
123
- const mergedIndex = [];
124
-
125
- for ( let i = 0; i < geometries.length; ++ i ) {
126
-
127
- const index = geometries[ i ].index;
128
-
129
- for ( let j = 0; j < index.count; ++ j ) {
130
-
131
- mergedIndex.push( index.getX( j ) + indexOffset );
132
-
133
- }
134
-
135
- indexOffset += geometries[ i ].attributes.position.count;
136
-
137
- }
138
-
139
- mergedGeometry.setIndex( mergedIndex );
140
-
141
- } // merge attributes
142
-
143
-
144
- for ( const name in attributes ) {
145
-
146
- const mergedAttribute = this.mergeBufferAttributes( attributes[ name ] );
147
-
148
- if ( ! mergedAttribute ) {
149
-
150
- console.error( 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the ' + name + ' attribute.' );
151
- return null;
152
-
153
- }
154
-
155
- mergedGeometry.setAttribute( name, mergedAttribute );
156
-
157
- } // merge morph attributes
158
-
159
-
160
- for ( const name in morphAttributes ) {
161
-
162
- const numMorphTargets = morphAttributes[ name ][ 0 ].length;
163
- if ( numMorphTargets === 0 ) break;
164
- mergedGeometry.morphAttributes = mergedGeometry.morphAttributes || {};
165
- mergedGeometry.morphAttributes[ name ] = [];
166
-
167
- for ( let i = 0; i < numMorphTargets; ++ i ) {
168
-
169
- const morphAttributesToMerge = [];
170
-
171
- for ( let j = 0; j < morphAttributes[ name ].length; ++ j ) {
172
-
173
- morphAttributesToMerge.push( morphAttributes[ name ][ j ][ i ] );
174
-
175
- }
176
-
177
- const mergedMorphAttribute = this.mergeBufferAttributes( morphAttributesToMerge );
178
-
179
- if ( ! mergedMorphAttribute ) {
180
-
181
- console.error( 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the ' + name + ' morphAttribute.' );
182
- return null;
183
-
184
- }
185
-
186
- mergedGeometry.morphAttributes[ name ].push( mergedMorphAttribute );
187
-
188
- }
189
-
190
- }
191
-
192
- return mergedGeometry;
193
-
194
- }
195
- /**
196
- * @param {Array<BufferAttribute>} attributes
197
- * @return {BufferAttribute}
198
- */
199
-
200
-
201
- static mergeBufferAttributes( attributes ) {
202
-
203
- let TypedArray;
204
- let itemSize;
205
- let normalized;
206
- let arrayLength = 0;
207
-
208
- for ( let i = 0; i < attributes.length; ++ i ) {
209
-
210
- const attribute = attributes[ i ];
211
-
212
- if ( attribute.isInterleavedBufferAttribute ) {
213
-
214
- console.error( 'THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. InterleavedBufferAttributes are not supported.' );
215
- return null;
216
-
217
- }
218
-
219
- if ( TypedArray === undefined ) TypedArray = attribute.array.constructor;
220
-
221
- if ( TypedArray !== attribute.array.constructor ) {
222
-
223
- console.error( 'THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. THREE.BufferAttribute.array must be of consistent array types across matching attributes.' );
224
- return null;
225
-
226
- }
227
-
228
- if ( itemSize === undefined ) itemSize = attribute.itemSize;
229
-
230
- if ( itemSize !== attribute.itemSize ) {
231
-
232
- console.error( 'THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. THREE.BufferAttribute.itemSize must be consistent across matching attributes.' );
233
- return null;
234
-
235
- }
236
-
237
- if ( normalized === undefined ) normalized = attribute.normalized;
238
-
239
- if ( normalized !== attribute.normalized ) {
240
-
241
- console.error( 'THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. THREE.BufferAttribute.normalized must be consistent across matching attributes.' );
242
- return null;
243
-
244
- }
245
-
246
- arrayLength += attribute.array.length;
247
-
248
- }
249
-
250
- const array = new TypedArray( arrayLength );
251
- let offset = 0;
252
-
253
- for ( let i = 0; i < attributes.length; ++ i ) {
254
-
255
- array.set( attributes[ i ].array, offset );
256
- offset += attributes[ i ].array.length;
257
-
258
- }
259
-
260
- return new THREE.BufferAttribute( array, itemSize, normalized );
261
-
262
- }
263
- /**
264
- * @param {Array<BufferAttribute>} attributes
265
- * @return {Array<InterleavedBufferAttribute>}
266
- */
267
-
268
-
269
- static interleaveAttributes( attributes ) {
270
-
271
- // Interleaves the provided attributes into an THREE.InterleavedBuffer and returns
272
- // a set of InterleavedBufferAttributes for each attribute
273
- let TypedArray;
274
- let arrayLength = 0;
275
- let stride = 0; // calculate the the length and type of the interleavedBuffer
276
-
277
- for ( let i = 0, l = attributes.length; i < l; ++ i ) {
278
-
279
- const attribute = attributes[ i ];
280
- if ( TypedArray === undefined ) TypedArray = attribute.array.constructor;
281
-
282
- if ( TypedArray !== attribute.array.constructor ) {
283
-
284
- console.error( 'AttributeBuffers of different types cannot be interleaved' );
285
- return null;
286
-
287
- }
288
-
289
- arrayLength += attribute.array.length;
290
- stride += attribute.itemSize;
291
-
292
- } // Create the set of buffer attributes
293
-
294
-
295
- const interleavedBuffer = new THREE.InterleavedBuffer( new TypedArray( arrayLength ), stride );
296
- let offset = 0;
297
- const res = [];
298
- const getters = [ 'getX', 'getY', 'getZ', 'getW' ];
299
- const setters = [ 'setX', 'setY', 'setZ', 'setW' ];
300
-
301
- for ( let j = 0, l = attributes.length; j < l; j ++ ) {
302
-
303
- const attribute = attributes[ j ];
304
- const itemSize = attribute.itemSize;
305
- const count = attribute.count;
306
- const iba = new THREE.InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, attribute.normalized );
307
- res.push( iba );
308
- offset += itemSize; // Move the data for each attribute into the new interleavedBuffer
309
- // at the appropriate offset
310
-
311
- for ( let c = 0; c < count; c ++ ) {
312
-
313
- for ( let k = 0; k < itemSize; k ++ ) {
314
-
315
- iba[ setters[ k ] ]( c, attribute[ getters[ k ] ]( c ) );
316
-
317
- }
318
-
319
- }
320
-
321
- }
322
-
323
- return res;
324
-
325
- }
326
- /**
327
- * @param {Array<BufferGeometry>} geometry
328
- * @return {number}
329
- */
330
-
331
-
332
- static estimateBytesUsed( geometry ) {
333
-
334
- // Return the estimated memory used by this geometry in bytes
335
- // Calculate using itemSize, count, and BYTES_PER_ELEMENT to account
336
- // for InterleavedBufferAttributes.
337
- let mem = 0;
338
-
339
- for ( const name in geometry.attributes ) {
340
-
341
- const attr = geometry.getAttribute( name );
342
- mem += attr.count * attr.itemSize * attr.array.BYTES_PER_ELEMENT;
343
-
344
- }
345
-
346
- const indices = geometry.getIndex();
347
- mem += indices ? indices.count * indices.itemSize * indices.array.BYTES_PER_ELEMENT : 0;
348
- return mem;
349
-
350
- }
351
- /**
352
- * @param {BufferGeometry} geometry
353
- * @param {number} tolerance
354
- * @return {BufferGeometry>}
355
- */
356
-
357
-
358
- static mergeVertices( geometry, tolerance = 1e-4 ) {
359
-
360
- tolerance = Math.max( tolerance, Number.EPSILON ); // Generate an index buffer if the geometry doesn't have one, or optimize it
361
- // if it's already available.
362
-
363
- const hashToIndex = {};
364
- const indices = geometry.getIndex();
365
- const positions = geometry.getAttribute( 'position' );
366
- const vertexCount = indices ? indices.count : positions.count; // next value for triangle indices
367
-
368
- let nextIndex = 0; // attributes and new attribute arrays
369
-
370
- const attributeNames = Object.keys( geometry.attributes );
371
- const attrArrays = {};
372
- const morphAttrsArrays = {};
373
- const newIndices = [];
374
- const getters = [ 'getX', 'getY', 'getZ', 'getW' ]; // initialize the arrays
375
-
376
- for ( let i = 0, l = attributeNames.length; i < l; i ++ ) {
377
-
378
- const name = attributeNames[ i ];
379
- attrArrays[ name ] = [];
380
- const morphAttr = geometry.morphAttributes[ name ];
381
-
382
- if ( morphAttr ) {
383
-
384
- morphAttrsArrays[ name ] = new Array( morphAttr.length ).fill().map( () => [] );
385
-
386
- }
387
-
388
- } // convert the error tolerance to an amount of decimal places to truncate to
389
-
390
-
391
- const decimalShift = Math.log10( 1 / tolerance );
392
- const shiftMultiplier = Math.pow( 10, decimalShift );
393
-
394
- for ( let i = 0; i < vertexCount; i ++ ) {
395
-
396
- const index = indices ? indices.getX( i ) : i; // Generate a hash for the vertex attributes at the current index 'i'
397
-
398
- let hash = '';
399
-
400
- for ( let j = 0, l = attributeNames.length; j < l; j ++ ) {
401
-
402
- const name = attributeNames[ j ];
403
- const attribute = geometry.getAttribute( name );
404
- const itemSize = attribute.itemSize;
405
-
406
- for ( let k = 0; k < itemSize; k ++ ) {
407
-
408
- // double tilde truncates the decimal value
409
- hash += `${~ ~ ( attribute[ getters[ k ] ]( index ) * shiftMultiplier )},`;
410
-
411
- }
412
-
413
- } // Add another reference to the vertex if it's already
414
- // used by another index
415
-
416
-
417
- if ( hash in hashToIndex ) {
418
-
419
- newIndices.push( hashToIndex[ hash ] );
420
-
421
- } else {
422
-
423
- // copy data to the new index in the attribute arrays
424
- for ( let j = 0, l = attributeNames.length; j < l; j ++ ) {
425
-
426
- const name = attributeNames[ j ];
427
- const attribute = geometry.getAttribute( name );
428
- const morphAttr = geometry.morphAttributes[ name ];
429
- const itemSize = attribute.itemSize;
430
- const newarray = attrArrays[ name ];
431
- const newMorphArrays = morphAttrsArrays[ name ];
432
-
433
- for ( let k = 0; k < itemSize; k ++ ) {
434
-
435
- const getterFunc = getters[ k ];
436
- newarray.push( attribute[ getterFunc ]( index ) );
437
-
438
- if ( morphAttr ) {
439
-
440
- for ( let m = 0, ml = morphAttr.length; m < ml; m ++ ) {
441
-
442
- newMorphArrays[ m ].push( morphAttr[ m ][ getterFunc ]( index ) );
443
-
444
- }
445
-
446
- }
447
-
448
- }
449
-
450
- }
451
-
452
- hashToIndex[ hash ] = nextIndex;
453
- newIndices.push( nextIndex );
454
- nextIndex ++;
455
-
456
- }
457
-
458
- } // Generate typed arrays from new attribute arrays and update
459
- // the attributeBuffers
460
-
461
-
462
- const result = geometry.clone();
463
-
464
- for ( let i = 0, l = attributeNames.length; i < l; i ++ ) {
465
-
466
- const name = attributeNames[ i ];
467
- const oldAttribute = geometry.getAttribute( name );
468
- const buffer = new oldAttribute.array.constructor( attrArrays[ name ] );
469
- const attribute = new THREE.BufferAttribute( buffer, oldAttribute.itemSize, oldAttribute.normalized );
470
- result.setAttribute( name, attribute ); // Update the attribute arrays
471
-
472
- if ( name in morphAttrsArrays ) {
473
-
474
- for ( let j = 0; j < morphAttrsArrays[ name ].length; j ++ ) {
475
-
476
- const oldMorphAttribute = geometry.morphAttributes[ name ][ j ];
477
- const buffer = new oldMorphAttribute.array.constructor( morphAttrsArrays[ name ][ j ] );
478
- const morphAttribute = new THREE.BufferAttribute( buffer, oldMorphAttribute.itemSize, oldMorphAttribute.normalized );
479
- result.morphAttributes[ name ][ j ] = morphAttribute;
480
-
481
- }
482
-
483
- }
484
-
485
- } // indices
486
-
487
-
488
- result.setIndex( newIndices );
489
- return result;
490
-
491
- }
492
- /**
493
- * @param {BufferGeometry} geometry
494
- * @param {number} drawMode
495
- * @return {BufferGeometry>}
496
- */
497
-
498
-
499
- static toTrianglesDrawMode( geometry, drawMode ) {
500
-
501
- if ( drawMode === THREE.TrianglesDrawMode ) {
502
-
503
- console.warn( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles.' );
504
- return geometry;
505
-
506
- }
507
-
508
- if ( drawMode === THREE.TriangleFanDrawMode || drawMode === THREE.TriangleStripDrawMode ) {
509
-
510
- let index = geometry.getIndex(); // generate index if not present
511
-
512
- if ( index === null ) {
513
-
514
- const indices = [];
515
- const position = geometry.getAttribute( 'position' );
516
-
517
- if ( position !== undefined ) {
518
-
519
- for ( let i = 0; i < position.count; i ++ ) {
520
-
521
- indices.push( i );
522
-
523
- }
524
-
525
- geometry.setIndex( indices );
526
- index = geometry.getIndex();
527
-
528
- } else {
529
-
530
- console.error( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible.' );
531
- return geometry;
532
-
533
- }
534
-
535
- } //
536
-
537
-
538
- const numberOfTriangles = index.count - 2;
539
- const newIndices = [];
540
-
541
- if ( drawMode === THREE.TriangleFanDrawMode ) {
542
-
543
- // gl.TRIANGLE_FAN
544
- for ( let i = 1; i <= numberOfTriangles; i ++ ) {
545
-
546
- newIndices.push( index.getX( 0 ) );
547
- newIndices.push( index.getX( i ) );
548
- newIndices.push( index.getX( i + 1 ) );
549
-
550
- }
551
-
552
- } else {
553
-
554
- // gl.TRIANGLE_STRIP
555
- for ( let i = 0; i < numberOfTriangles; i ++ ) {
556
-
557
- if ( i % 2 === 0 ) {
558
-
559
- newIndices.push( index.getX( i ) );
560
- newIndices.push( index.getX( i + 1 ) );
561
- newIndices.push( index.getX( i + 2 ) );
562
-
563
- } else {
564
-
565
- newIndices.push( index.getX( i + 2 ) );
566
- newIndices.push( index.getX( i + 1 ) );
567
- newIndices.push( index.getX( i ) );
568
-
569
- }
570
-
571
- }
572
-
573
- }
574
-
575
- if ( newIndices.length / 3 !== numberOfTriangles ) {
576
-
577
- console.error( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.' );
578
-
579
- } // build final geometry
580
-
581
-
582
- const newGeometry = geometry.clone();
583
- newGeometry.setIndex( newIndices );
584
- newGeometry.clearGroups();
585
- return newGeometry;
586
-
587
- } else {
588
-
589
- console.error( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:', drawMode );
590
- return geometry;
591
-
592
- }
593
-
594
- }
595
- /**
596
- * Calculates the morphed attributes of a morphed/skinned THREE.BufferGeometry.
597
- * Helpful for Raytracing or Decals.
598
- * @param {Mesh | Line | Points} object An instance of Mesh, Line or Points.
599
- * @return {Object} An Object with original position/normal attributes and morphed ones.
600
- */
601
-
602
-
603
- static computeMorphedAttributes( object ) {
604
-
605
- if ( object.geometry.isBufferGeometry !== true ) {
606
-
607
- console.error( 'THREE.BufferGeometryUtils: Geometry is not of type THREE.BufferGeometry.' );
608
- return null;
609
-
610
- }
611
-
612
- const _vA = new THREE.Vector3();
613
-
614
- const _vB = new THREE.Vector3();
615
-
616
- const _vC = new THREE.Vector3();
617
-
618
- const _tempA = new THREE.Vector3();
619
-
620
- const _tempB = new THREE.Vector3();
621
-
622
- const _tempC = new THREE.Vector3();
623
-
624
- const _morphA = new THREE.Vector3();
625
-
626
- const _morphB = new THREE.Vector3();
627
-
628
- const _morphC = new THREE.Vector3();
629
-
630
- function _calculateMorphedAttributeData( object, material, attribute, morphAttribute, morphTargetsRelative, a, b, c, modifiedAttributeArray ) {
631
-
632
- _vA.fromBufferAttribute( attribute, a );
633
-
634
- _vB.fromBufferAttribute( attribute, b );
635
-
636
- _vC.fromBufferAttribute( attribute, c );
637
-
638
- const morphInfluences = object.morphTargetInfluences;
639
-
640
- if ( material.morphTargets && morphAttribute && morphInfluences ) {
641
-
642
- _morphA.set( 0, 0, 0 );
643
-
644
- _morphB.set( 0, 0, 0 );
645
-
646
- _morphC.set( 0, 0, 0 );
647
-
648
- for ( let i = 0, il = morphAttribute.length; i < il; i ++ ) {
649
-
650
- const influence = morphInfluences[ i ];
651
- const morph = morphAttribute[ i ];
652
- if ( influence === 0 ) continue;
653
-
654
- _tempA.fromBufferAttribute( morph, a );
655
-
656
- _tempB.fromBufferAttribute( morph, b );
657
-
658
- _tempC.fromBufferAttribute( morph, c );
659
-
660
- if ( morphTargetsRelative ) {
661
-
662
- _morphA.addScaledVector( _tempA, influence );
663
-
664
- _morphB.addScaledVector( _tempB, influence );
665
-
666
- _morphC.addScaledVector( _tempC, influence );
667
-
668
- } else {
669
-
670
- _morphA.addScaledVector( _tempA.sub( _vA ), influence );
671
-
672
- _morphB.addScaledVector( _tempB.sub( _vB ), influence );
673
-
674
- _morphC.addScaledVector( _tempC.sub( _vC ), influence );
675
-
676
- }
677
-
678
- }
679
-
680
- _vA.add( _morphA );
681
-
682
- _vB.add( _morphB );
683
-
684
- _vC.add( _morphC );
685
-
686
- }
687
-
688
- if ( object.isSkinnedMesh ) {
689
-
690
- object.boneTransform( a, _vA );
691
- object.boneTransform( b, _vB );
692
- object.boneTransform( c, _vC );
693
-
694
- }
695
-
696
- modifiedAttributeArray[ a * 3 + 0 ] = _vA.x;
697
- modifiedAttributeArray[ a * 3 + 1 ] = _vA.y;
698
- modifiedAttributeArray[ a * 3 + 2 ] = _vA.z;
699
- modifiedAttributeArray[ b * 3 + 0 ] = _vB.x;
700
- modifiedAttributeArray[ b * 3 + 1 ] = _vB.y;
701
- modifiedAttributeArray[ b * 3 + 2 ] = _vB.z;
702
- modifiedAttributeArray[ c * 3 + 0 ] = _vC.x;
703
- modifiedAttributeArray[ c * 3 + 1 ] = _vC.y;
704
- modifiedAttributeArray[ c * 3 + 2 ] = _vC.z;
705
-
706
- }
707
-
708
- const geometry = object.geometry;
709
- const material = object.material;
710
- let a, b, c;
711
- const index = geometry.index;
712
- const positionAttribute = geometry.attributes.position;
713
- const morphPosition = geometry.morphAttributes.position;
714
- const morphTargetsRelative = geometry.morphTargetsRelative;
715
- const normalAttribute = geometry.attributes.normal;
716
- const morphNormal = geometry.morphAttributes.position;
717
- const groups = geometry.groups;
718
- const drawRange = geometry.drawRange;
719
- let i, j, il, jl;
720
- let group, groupMaterial;
721
- let start, end;
722
- const modifiedPosition = new Float32Array( positionAttribute.count * positionAttribute.itemSize );
723
- const modifiedNormal = new Float32Array( normalAttribute.count * normalAttribute.itemSize );
724
-
725
- if ( index !== null ) {
726
-
727
- // indexed buffer geometry
728
- if ( Array.isArray( material ) ) {
729
-
730
- for ( i = 0, il = groups.length; i < il; i ++ ) {
731
-
732
- group = groups[ i ];
733
- groupMaterial = material[ group.materialIndex ];
734
- start = Math.max( group.start, drawRange.start );
735
- end = Math.min( group.start + group.count, drawRange.start + drawRange.count );
736
-
737
- for ( j = start, jl = end; j < jl; j += 3 ) {
738
-
739
- a = index.getX( j );
740
- b = index.getX( j + 1 );
741
- c = index.getX( j + 2 );
742
-
743
- _calculateMorphedAttributeData( object, groupMaterial, positionAttribute, morphPosition, morphTargetsRelative, a, b, c, modifiedPosition );
744
-
745
- _calculateMorphedAttributeData( object, groupMaterial, normalAttribute, morphNormal, morphTargetsRelative, a, b, c, modifiedNormal );
746
-
747
- }
748
-
749
- }
750
-
751
- } else {
752
-
753
- start = Math.max( 0, drawRange.start );
754
- end = Math.min( index.count, drawRange.start + drawRange.count );
755
-
756
- for ( i = start, il = end; i < il; i += 3 ) {
757
-
758
- a = index.getX( i );
759
- b = index.getX( i + 1 );
760
- c = index.getX( i + 2 );
761
-
762
- _calculateMorphedAttributeData( object, material, positionAttribute, morphPosition, morphTargetsRelative, a, b, c, modifiedPosition );
763
-
764
- _calculateMorphedAttributeData( object, material, normalAttribute, morphNormal, morphTargetsRelative, a, b, c, modifiedNormal );
765
-
766
- }
767
-
768
- }
769
-
770
- } else if ( positionAttribute !== undefined ) {
771
-
772
- // non-indexed buffer geometry
773
- if ( Array.isArray( material ) ) {
774
-
775
- for ( i = 0, il = groups.length; i < il; i ++ ) {
776
-
777
- group = groups[ i ];
778
- groupMaterial = material[ group.materialIndex ];
779
- start = Math.max( group.start, drawRange.start );
780
- end = Math.min( group.start + group.count, drawRange.start + drawRange.count );
781
-
782
- for ( j = start, jl = end; j < jl; j += 3 ) {
783
-
784
- a = j;
785
- b = j + 1;
786
- c = j + 2;
787
-
788
- _calculateMorphedAttributeData( object, groupMaterial, positionAttribute, morphPosition, morphTargetsRelative, a, b, c, modifiedPosition );
789
-
790
- _calculateMorphedAttributeData( object, groupMaterial, normalAttribute, morphNormal, morphTargetsRelative, a, b, c, modifiedNormal );
791
-
792
- }
793
-
794
- }
795
-
796
- } else {
797
-
798
- start = Math.max( 0, drawRange.start );
799
- end = Math.min( positionAttribute.count, drawRange.start + drawRange.count );
800
-
801
- for ( i = start, il = end; i < il; i += 3 ) {
802
-
803
- a = i;
804
- b = i + 1;
805
- c = i + 2;
806
-
807
- _calculateMorphedAttributeData( object, material, positionAttribute, morphPosition, morphTargetsRelative, a, b, c, modifiedPosition );
808
-
809
- _calculateMorphedAttributeData( object, material, normalAttribute, morphNormal, morphTargetsRelative, a, b, c, modifiedNormal );
810
-
811
- }
812
-
813
- }
814
-
815
- }
816
-
817
- const morphedPositionAttribute = new THREE.Float32BufferAttribute( modifiedPosition, 3 );
818
- const morphedNormalAttribute = new THREE.Float32BufferAttribute( modifiedNormal, 3 );
819
- return {
820
- positionAttribute: positionAttribute,
821
- normalAttribute: normalAttribute,
822
- morphedPositionAttribute: morphedPositionAttribute,
823
- morphedNormalAttribute: morphedNormalAttribute
824
- };
825
-
826
- }
827
-
828
- }
829
-
830
- THREE.BufferGeometryUtils = BufferGeometryUtils;
831
-
832
- } )();