@react-three/drei 9.106.0 → 9.106.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 (116) hide show
  1. package/README.md +38 -41
  2. package/core/Caustics.cjs.js +1 -1
  3. package/core/Caustics.js +2 -2
  4. package/core/Cloud.cjs.js +1 -1
  5. package/core/Cloud.js +1 -1
  6. package/core/CubeCamera.cjs.js +1 -1
  7. package/core/CubeCamera.d.ts +15 -3
  8. package/core/CubeCamera.js +47 -4
  9. package/core/CubeTexture.cjs.js +1 -0
  10. package/core/CubeTexture.d.ts +15 -0
  11. package/core/{useCubeTexture.js → CubeTexture.js} +12 -1
  12. package/core/DetectGPU.cjs.js +1 -0
  13. package/core/DetectGPU.d.ts +8 -0
  14. package/core/DetectGPU.js +14 -0
  15. package/core/Example.d.ts +1 -1
  16. package/core/Example.js +3 -0
  17. package/core/Fbo.cjs.js +1 -0
  18. package/core/{useFBO.d.ts → Fbo.d.ts} +6 -0
  19. package/core/{useFBO.js → Fbo.js} +10 -1
  20. package/core/Fbx.cjs.js +1 -0
  21. package/core/Fbx.d.ts +11 -0
  22. package/core/Fbx.js +23 -0
  23. package/core/GizmoHelper.cjs.js +1 -1
  24. package/core/GizmoViewcube.cjs.js +1 -1
  25. package/core/GizmoViewport.cjs.js +1 -1
  26. package/core/Gltf.cjs.js +1 -1
  27. package/core/Gltf.d.ts +17 -5
  28. package/core/Gltf.js +37 -3
  29. package/core/Helper.cjs.js +1 -1
  30. package/core/Helper.d.ts +3 -1
  31. package/core/Helper.js +35 -24
  32. package/core/Image.cjs.js +1 -1
  33. package/core/Image.js +1 -1
  34. package/core/Ktx2.cjs.js +1 -0
  35. package/core/{useKTX2.d.ts → Ktx2.d.ts} +6 -0
  36. package/core/{useKTX2.js → Ktx2.js} +15 -3
  37. package/core/MatcapTexture.cjs.js +1 -0
  38. package/core/MatcapTexture.d.ts +9 -0
  39. package/core/{useMatcapTexture.js → MatcapTexture.js} +14 -2
  40. package/core/MeshPortalMaterial.cjs.js +1 -1
  41. package/core/MeshPortalMaterial.js +1 -1
  42. package/core/MeshTransmissionMaterial.cjs.js +1 -1
  43. package/core/MeshTransmissionMaterial.js +1 -1
  44. package/core/NormalTexture.cjs.js +1 -0
  45. package/core/NormalTexture.d.ts +14 -0
  46. package/core/{useNormalTexture.js → NormalTexture.js} +14 -2
  47. package/core/OrthographicCamera.cjs.js +1 -1
  48. package/core/OrthographicCamera.js +1 -1
  49. package/core/PerspectiveCamera.cjs.js +1 -1
  50. package/core/PerspectiveCamera.js +1 -1
  51. package/core/Progress.cjs.js +1 -0
  52. package/core/{useProgress.d.ts → Progress.d.ts} +4 -0
  53. package/core/{useProgress.js → Progress.js} +11 -1
  54. package/core/RenderTexture.cjs.js +1 -1
  55. package/core/RenderTexture.js +1 -1
  56. package/core/Texture.cjs.js +1 -0
  57. package/core/{useTexture.d.ts → Texture.d.ts} +10 -4
  58. package/core/{useTexture.js → Texture.js} +18 -5
  59. package/core/TrailTexture.cjs.js +1 -0
  60. package/core/{useTrailTexture.d.ts → TrailTexture.d.ts} +4 -0
  61. package/core/{useTrailTexture.js → TrailTexture.js} +14 -3
  62. package/core/VideoTexture.cjs.js +1 -0
  63. package/core/VideoTexture.d.ts +18 -0
  64. package/core/{useVideoTexture.js → VideoTexture.js} +25 -23
  65. package/core/index.cjs.js +1 -1
  66. package/core/index.d.ts +12 -15
  67. package/core/index.js +16 -19
  68. package/core/useDepthBuffer.cjs.js +1 -1
  69. package/core/useDepthBuffer.js +1 -1
  70. package/core/useSpriteLoader.cjs.js +1 -1
  71. package/core/useSpriteLoader.d.ts +1 -0
  72. package/core/useSpriteLoader.js +82 -9
  73. package/index.cjs.js +1 -1
  74. package/index.js +16 -19
  75. package/native/index.cjs.js +1 -1
  76. package/native/index.js +16 -19
  77. package/package.json +3 -3
  78. package/react-three-drei-0.0.0-semantic-release.tgz +0 -0
  79. package/web/FaceControls.cjs.js +1 -1
  80. package/web/FaceControls.d.ts +1 -1
  81. package/web/FaceControls.js +12 -1
  82. package/web/Loader.cjs.js +1 -1
  83. package/web/Loader.js +1 -1
  84. package/web/index.cjs.js +1 -1
  85. package/web/index.js +16 -19
  86. package/core/useCubeCamera.cjs.js +0 -1
  87. package/core/useCubeCamera.d.ts +0 -14
  88. package/core/useCubeCamera.js +0 -49
  89. package/core/useCubeTexture.cjs.js +0 -1
  90. package/core/useCubeTexture.d.ts +0 -9
  91. package/core/useDetectGPU.cjs.js +0 -1
  92. package/core/useDetectGPU.d.ts +0 -2
  93. package/core/useDetectGPU.js +0 -6
  94. package/core/useFBO.cjs.js +0 -1
  95. package/core/useFBX.cjs.js +0 -1
  96. package/core/useFBX.d.ts +0 -6
  97. package/core/useFBX.js +0 -10
  98. package/core/useGLTF.cjs.js +0 -1
  99. package/core/useGLTF.d.ts +0 -8
  100. package/core/useGLTF.js +0 -32
  101. package/core/useHelper.cjs.js +0 -1
  102. package/core/useHelper.d.ts +0 -11
  103. package/core/useHelper.js +0 -30
  104. package/core/useKTX2.cjs.js +0 -1
  105. package/core/useMatcapTexture.cjs.js +0 -1
  106. package/core/useMatcapTexture.d.ts +0 -2
  107. package/core/useNormalTexture.cjs.js +0 -1
  108. package/core/useNormalTexture.d.ts +0 -8
  109. package/core/useProgress.cjs.js +0 -1
  110. package/core/useTexture.cjs.js +0 -1
  111. package/core/useTrailTexture.cjs.js +0 -1
  112. package/core/useVideoTexture.cjs.js +0 -1
  113. package/core/useVideoTexture.d.ts +0 -12
  114. /package/core/{useBVH.cjs.js → Bvh.cjs.js} +0 -0
  115. /package/core/{useBVH.d.ts → Bvh.d.ts} +0 -0
  116. /package/core/{useBVH.js → Bvh.js} +0 -0
@@ -18,6 +18,14 @@ const getFirstItem = param => {
18
18
  };
19
19
  }
20
20
  };
21
+ const checkIfFrameIsEmpty = frameData => {
22
+ for (let i = 3; i < frameData.length; i += 4) {
23
+ if (frameData[i] !== 0) {
24
+ return false;
25
+ }
26
+ }
27
+ return true;
28
+ };
21
29
  const calculateAspectRatio = (width, height, factor, v) => {
22
30
  const adaptedHeight = height * (v.aspect > width / height ? v.width / width : v.height / height);
23
31
  const adaptedWidth = width * (v.aspect > width / height ? v.width / width : v.height / height);
@@ -94,9 +102,14 @@ function useSpriteLoader(input, json, animationNames, numberOfFrames, onLoad) {
94
102
  //get size from texture
95
103
  const width = _spriteTexture.image.width;
96
104
  const height = _spriteTexture.image.height;
97
- const frameWidth = width / numberOfFrames;
98
- const frameHeight = height;
99
105
  totalFrames.current = numberOfFrames;
106
+ const {
107
+ rows,
108
+ columns,
109
+ frameWidth,
110
+ frameHeight,
111
+ emptyFrames
112
+ } = getRowsAndColumns(_spriteTexture, numberOfFrames);
100
113
  spriteDataRef.current = {
101
114
  frames: [],
102
115
  meta: {
@@ -105,16 +118,23 @@ function useSpriteLoader(input, json, animationNames, numberOfFrames, onLoad) {
105
118
  w: width,
106
119
  h: height
107
120
  },
121
+ rows,
122
+ columns,
123
+ frameWidth,
124
+ frameHeight,
108
125
  scale: '1'
109
126
  }
110
127
  };
111
- if (parseInt(frameWidth.toString(), 10) === frameWidth) {
112
- // if it fits
113
- for (let i = 0; i < numberOfFrames; i++) {
128
+ for (let row = 0; row < rows; row++) {
129
+ for (let col = 0; col < columns; col++) {
130
+ const isExcluded = (emptyFrames !== null && emptyFrames !== void 0 ? emptyFrames : []).some(coord => coord.row === row && coord.col === col);
131
+ if (isExcluded) {
132
+ continue;
133
+ }
114
134
  spriteDataRef.current.frames.push({
115
135
  frame: {
116
- x: i * frameWidth,
117
- y: 0,
136
+ x: col * frameWidth,
137
+ y: row * frameHeight,
118
138
  w: frameWidth,
119
139
  h: frameHeight
120
140
  },
@@ -128,7 +148,7 @@ function useSpriteLoader(input, json, animationNames, numberOfFrames, onLoad) {
128
148
  },
129
149
  sourceSize: {
130
150
  w: frameWidth,
131
- h: height
151
+ h: frameHeight
132
152
  }
133
153
  });
134
154
  }
@@ -157,6 +177,59 @@ function useSpriteLoader(input, json, animationNames, numberOfFrames, onLoad) {
157
177
  aspect: aspect
158
178
  });
159
179
  };
180
+ const getRowsAndColumns = (texture, totalFrames) => {
181
+ if (texture.image) {
182
+ const canvas = document.createElement('canvas');
183
+ const ctx = canvas.getContext('2d');
184
+ canvas.width = texture.image.width;
185
+ canvas.height = texture.image.height;
186
+ ctx.drawImage(texture.image, 0, 0);
187
+ const width = texture.image.width;
188
+ const height = texture.image.height;
189
+
190
+ // Calculate rows and columns based on the number of frames and image dimensions
191
+ const cols = Math.round(Math.sqrt(totalFrames * (width / height)));
192
+ const rows = Math.round(totalFrames / cols);
193
+ const frameWidth = width / cols;
194
+ const frameHeight = height / rows;
195
+ const emptyFrames = [];
196
+ for (let row = 0; row < rows; row++) {
197
+ for (let col = 0; col < cols; col++) {
198
+ const frameIndex = row * cols + col;
199
+ if (frameIndex >= totalFrames) {
200
+ emptyFrames.push({
201
+ row,
202
+ col
203
+ });
204
+ continue;
205
+ }
206
+ const frameData = ctx.getImageData(col * frameWidth, row * frameHeight, frameWidth, frameHeight).data;
207
+ const isEmpty = checkIfFrameIsEmpty(frameData);
208
+ if (isEmpty) {
209
+ emptyFrames.push({
210
+ row,
211
+ col
212
+ });
213
+ }
214
+ }
215
+ }
216
+ return {
217
+ rows,
218
+ columns: cols,
219
+ frameWidth,
220
+ frameHeight,
221
+ emptyFrames
222
+ };
223
+ } else {
224
+ return {
225
+ rows: 0,
226
+ columns: 0,
227
+ frameWidth: 0,
228
+ frameHeight: 0,
229
+ emptyFrames: []
230
+ };
231
+ }
232
+ };
160
233
 
161
234
  // for frame based JSON Hash sprite data
162
235
  const parseFrames = () => {
@@ -240,4 +313,4 @@ function useSpriteLoader(input, json, animationNames, numberOfFrames, onLoad) {
240
313
  useSpriteLoader.preload = url => useLoader.preload(TextureLoader, url);
241
314
  useSpriteLoader.clear = input => useLoader.clear(TextureLoader, input);
242
315
 
243
- export { calculateAspectRatio, getFirstItem, useSpriteLoader };
316
+ export { calculateAspectRatio, checkIfFrameIsEmpty, getFirstItem, useSpriteLoader };