@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.
- package/README.md +38 -41
- package/core/Caustics.cjs.js +1 -1
- package/core/Caustics.js +2 -2
- package/core/Cloud.cjs.js +1 -1
- package/core/Cloud.js +1 -1
- package/core/CubeCamera.cjs.js +1 -1
- package/core/CubeCamera.d.ts +15 -3
- package/core/CubeCamera.js +47 -4
- package/core/CubeTexture.cjs.js +1 -0
- package/core/CubeTexture.d.ts +15 -0
- package/core/{useCubeTexture.js → CubeTexture.js} +12 -1
- package/core/DetectGPU.cjs.js +1 -0
- package/core/DetectGPU.d.ts +8 -0
- package/core/DetectGPU.js +14 -0
- package/core/Example.d.ts +1 -1
- package/core/Example.js +3 -0
- package/core/Fbo.cjs.js +1 -0
- package/core/{useFBO.d.ts → Fbo.d.ts} +6 -0
- package/core/{useFBO.js → Fbo.js} +10 -1
- package/core/Fbx.cjs.js +1 -0
- package/core/Fbx.d.ts +11 -0
- package/core/Fbx.js +23 -0
- package/core/GizmoHelper.cjs.js +1 -1
- package/core/GizmoViewcube.cjs.js +1 -1
- package/core/GizmoViewport.cjs.js +1 -1
- package/core/Gltf.cjs.js +1 -1
- package/core/Gltf.d.ts +17 -5
- package/core/Gltf.js +37 -3
- package/core/Helper.cjs.js +1 -1
- package/core/Helper.d.ts +3 -1
- package/core/Helper.js +35 -24
- package/core/Image.cjs.js +1 -1
- package/core/Image.js +1 -1
- package/core/Ktx2.cjs.js +1 -0
- package/core/{useKTX2.d.ts → Ktx2.d.ts} +6 -0
- package/core/{useKTX2.js → Ktx2.js} +15 -3
- package/core/MatcapTexture.cjs.js +1 -0
- package/core/MatcapTexture.d.ts +9 -0
- package/core/{useMatcapTexture.js → MatcapTexture.js} +14 -2
- package/core/MeshPortalMaterial.cjs.js +1 -1
- package/core/MeshPortalMaterial.js +1 -1
- package/core/MeshTransmissionMaterial.cjs.js +1 -1
- package/core/MeshTransmissionMaterial.js +1 -1
- package/core/NormalTexture.cjs.js +1 -0
- package/core/NormalTexture.d.ts +14 -0
- package/core/{useNormalTexture.js → NormalTexture.js} +14 -2
- package/core/OrthographicCamera.cjs.js +1 -1
- package/core/OrthographicCamera.js +1 -1
- package/core/PerspectiveCamera.cjs.js +1 -1
- package/core/PerspectiveCamera.js +1 -1
- package/core/Progress.cjs.js +1 -0
- package/core/{useProgress.d.ts → Progress.d.ts} +4 -0
- package/core/{useProgress.js → Progress.js} +11 -1
- package/core/RenderTexture.cjs.js +1 -1
- package/core/RenderTexture.js +1 -1
- package/core/Texture.cjs.js +1 -0
- package/core/{useTexture.d.ts → Texture.d.ts} +10 -4
- package/core/{useTexture.js → Texture.js} +18 -5
- package/core/TrailTexture.cjs.js +1 -0
- package/core/{useTrailTexture.d.ts → TrailTexture.d.ts} +4 -0
- package/core/{useTrailTexture.js → TrailTexture.js} +14 -3
- package/core/VideoTexture.cjs.js +1 -0
- package/core/VideoTexture.d.ts +18 -0
- package/core/{useVideoTexture.js → VideoTexture.js} +25 -23
- package/core/index.cjs.js +1 -1
- package/core/index.d.ts +12 -15
- package/core/index.js +16 -19
- package/core/useDepthBuffer.cjs.js +1 -1
- package/core/useDepthBuffer.js +1 -1
- package/core/useSpriteLoader.cjs.js +1 -1
- package/core/useSpriteLoader.d.ts +1 -0
- package/core/useSpriteLoader.js +82 -9
- package/index.cjs.js +1 -1
- package/index.js +16 -19
- package/native/index.cjs.js +1 -1
- package/native/index.js +16 -19
- package/package.json +3 -3
- package/react-three-drei-0.0.0-semantic-release.tgz +0 -0
- package/web/FaceControls.cjs.js +1 -1
- package/web/FaceControls.d.ts +1 -1
- package/web/FaceControls.js +12 -1
- package/web/Loader.cjs.js +1 -1
- package/web/Loader.js +1 -1
- package/web/index.cjs.js +1 -1
- package/web/index.js +16 -19
- package/core/useCubeCamera.cjs.js +0 -1
- package/core/useCubeCamera.d.ts +0 -14
- package/core/useCubeCamera.js +0 -49
- package/core/useCubeTexture.cjs.js +0 -1
- package/core/useCubeTexture.d.ts +0 -9
- package/core/useDetectGPU.cjs.js +0 -1
- package/core/useDetectGPU.d.ts +0 -2
- package/core/useDetectGPU.js +0 -6
- package/core/useFBO.cjs.js +0 -1
- package/core/useFBX.cjs.js +0 -1
- package/core/useFBX.d.ts +0 -6
- package/core/useFBX.js +0 -10
- package/core/useGLTF.cjs.js +0 -1
- package/core/useGLTF.d.ts +0 -8
- package/core/useGLTF.js +0 -32
- package/core/useHelper.cjs.js +0 -1
- package/core/useHelper.d.ts +0 -11
- package/core/useHelper.js +0 -30
- package/core/useKTX2.cjs.js +0 -1
- package/core/useMatcapTexture.cjs.js +0 -1
- package/core/useMatcapTexture.d.ts +0 -2
- package/core/useNormalTexture.cjs.js +0 -1
- package/core/useNormalTexture.d.ts +0 -8
- package/core/useProgress.cjs.js +0 -1
- package/core/useTexture.cjs.js +0 -1
- package/core/useTrailTexture.cjs.js +0 -1
- package/core/useVideoTexture.cjs.js +0 -1
- package/core/useVideoTexture.d.ts +0 -12
- /package/core/{useBVH.cjs.js → Bvh.cjs.js} +0 -0
- /package/core/{useBVH.d.ts → Bvh.d.ts} +0 -0
- /package/core/{useBVH.js → Bvh.js} +0 -0
package/core/useSpriteLoader.js
CHANGED
|
@@ -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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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:
|
|
117
|
-
y:
|
|
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:
|
|
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 };
|