@react-three/drei 9.107.0 → 9.107.1
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 +5 -5
- package/core/Bvh.d.ts +1 -0
- package/core/Edges.cjs.js +1 -1
- package/core/Edges.d.ts +2 -1
- package/core/Edges.js +12 -12
- package/core/Fbo.d.ts +1 -1
- package/core/Ktx2.d.ts +1 -1
- package/core/MatcapTexture.d.ts +1 -1
- package/core/NormalTexture.d.ts +1 -1
- package/core/Texture.d.ts +1 -1
- package/core/TrailTexture.d.ts +1 -1
- package/core/VideoTexture.d.ts +2 -6
- package/core/useEnvironment.d.ts +2 -2
- package/core/useSpriteLoader.cjs.js +1 -1
- package/core/useSpriteLoader.js +48 -2
- package/index.cjs.js +1 -1
- package/package.json +1 -1
- package/react-three-drei-0.0.0-semantic-release.tgz +0 -0
package/README.md
CHANGED
|
@@ -373,7 +373,7 @@ If available controls have damping enabled by default, they manage their own upd
|
|
|
373
373
|
const controls = useThree((state) => state.controls)
|
|
374
374
|
```
|
|
375
375
|
|
|
376
|
-
Drei currently exports OrbitControls [](https://drei.vercel.app/?path=/story/controls-orbitcontrols--orbit-controls-story), MapControls [](https://drei.vercel.app/?path=/story/controls-mapcontrols--map-controls-
|
|
376
|
+
Drei currently exports OrbitControls [](https://drei.vercel.app/?path=/story/controls-orbitcontrols--orbit-controls-story), MapControls [](https://drei.vercel.app/?path=/story/controls-mapcontrols--map-controls-st), TrackballControls, ArcballControls, FlyControls, DeviceOrientationControls, PointerLockControls [](https://drei.vercel.app/?path=/story/controls-pointerlockcontrols--pointer-lock-controls-scene-st), FirstPersonControls [](https://drei.vercel.app/?path=/story/controls-firstpersoncontrols--first-person-controls-story) CameraControls [](https://drei.vercel.app/?path=/story/controls-cameracontrols--camera-controls-story) and FaceControls [](https://drei.vercel.app/?path=/story/controls-facecontrols)
|
|
377
377
|
|
|
378
378
|
All controls react to the default camera. If you have a `<PerspectiveCamera makeDefault />` in your scene, they will control it. If you need to inject an imperative camera or one that isn't the default, use the `camera` prop: `<OrbitControls camera={MyCamera} />`.
|
|
379
379
|
|
|
@@ -1188,7 +1188,7 @@ A triangle that fills the screen, ideal for full-screen fragment shader work (ra
|
|
|
1188
1188
|
|
|
1189
1189
|
#### Line
|
|
1190
1190
|
|
|
1191
|
-
[](https://drei.vercel.app/?path=/story/
|
|
1191
|
+
[](https://drei.vercel.app/?path=/story/shapes-line--basic-line-st)
|
|
1192
1192
|
|
|
1193
1193
|
Renders a THREE.Line2 or THREE.LineSegments2 (depending on the value of `segments`).
|
|
1194
1194
|
|
|
@@ -1207,7 +1207,7 @@ Renders a THREE.Line2 or THREE.LineSegments2 (depending on the value of `segment
|
|
|
1207
1207
|
|
|
1208
1208
|
#### QuadraticBezierLine
|
|
1209
1209
|
|
|
1210
|
-
[](https://drei.vercel.app/?path=/story/
|
|
1210
|
+
[](https://drei.vercel.app/?path=/story/shapes-line--quadratic-bezier-st)
|
|
1211
1211
|
|
|
1212
1212
|
<p>
|
|
1213
1213
|
<a href="https://codesandbox.io/s/2ij9u"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/2ij9u/screenshot.png" alt="Demo"/></a>
|
|
@@ -1246,7 +1246,7 @@ return <QuadraticBezierLine ref={ref} />
|
|
|
1246
1246
|
|
|
1247
1247
|
#### CubicBezierLine
|
|
1248
1248
|
|
|
1249
|
-
[](https://drei.vercel.app/?path=/story/
|
|
1249
|
+
[](https://drei.vercel.app/?path=/story/shapes-line--cubic-bezier-st)
|
|
1250
1250
|
|
|
1251
1251
|
Renders a THREE.Line2 using THREE.CubicBezierCurve3 for interpolation.
|
|
1252
1252
|
|
|
@@ -1267,7 +1267,7 @@ Renders a THREE.Line2 using THREE.CubicBezierCurve3 for interpolation.
|
|
|
1267
1267
|
|
|
1268
1268
|
#### CatmullRomLine
|
|
1269
1269
|
|
|
1270
|
-
[](https://drei.vercel.app/?path=/story/
|
|
1270
|
+
[](https://drei.vercel.app/?path=/story/shapes-line--catmull-rom-st)
|
|
1271
1271
|
|
|
1272
1272
|
Renders a THREE.Line2 using THREE.CatmullRomCurve3 for interpolation.
|
|
1273
1273
|
|
package/core/Bvh.d.ts
CHANGED
package/core/Edges.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),t=require("react"),r=require("three"),n=require("./Line.cjs.js");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function s(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}require("@react-three/fiber"),require("three-stdlib");var c=u(e),i=s(t),o=s(r);const a=i.forwardRef((({threshold:e=15,...
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),t=require("react"),r=require("three"),n=require("./Line.cjs.js");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function s(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}require("@react-three/fiber"),require("three-stdlib");var c=u(e),i=s(t),o=s(r);const a=i.forwardRef((({threshold:e=15,geometry:t,...r},u)=>{const s=i.useRef(null);i.useImperativeHandle(u,(()=>s.current),[]);const a=i.useMemo((()=>[0,0,0,1,0,0]),[]),f=i.useRef(),l=i.useRef();return i.useLayoutEffect((()=>{const r=s.current.parent,n=null!=t?t:null==r?void 0:r.geometry;if(!n)return;if(f.current===n&&l.current===e)return;f.current=n,l.current=e;const u=new o.EdgesGeometry(n,e).attributes.position.array;s.current.geometry.setPositions(u),s.current.geometry.attributes.instanceStart.needsUpdate=!0,s.current.geometry.attributes.instanceEnd.needsUpdate=!0,s.current.computeLineDistances()})),i.createElement(n.Line,c.default({segments:!0,points:a,ref:s,raycast:()=>null},r))}));exports.Edges=a;
|
package/core/Edges.d.ts
CHANGED
|
@@ -6,7 +6,8 @@ export type EdgesRef = THREE.Mesh<LineSegmentsGeometry, LineMaterial>;
|
|
|
6
6
|
export type EdgesProps = Partial<ThreeElements['mesh']> & {
|
|
7
7
|
threshold?: number;
|
|
8
8
|
lineWidth?: number;
|
|
9
|
-
} & Omit<LineMaterialParameters, 'vertexColors' | 'color'> & Omit<ReactThreeFiber.Object3DNode<Line2, typeof Line2>, 'args'> & Omit<ReactThreeFiber.Object3DNode<LineMaterial, [LineMaterialParameters]>, 'color' | 'vertexColors' | 'args'> & {
|
|
9
|
+
} & Omit<LineMaterialParameters, 'vertexColors' | 'color'> & Omit<ReactThreeFiber.Object3DNode<Line2, typeof Line2>, 'args' | 'geometry'> & Omit<ReactThreeFiber.Object3DNode<LineMaterial, [LineMaterialParameters]>, 'color' | 'vertexColors' | 'args'> & {
|
|
10
|
+
geometry?: THREE.BufferGeometry;
|
|
10
11
|
color?: THREE.ColorRepresentation;
|
|
11
12
|
};
|
|
12
13
|
export declare const Edges: ForwardRefComponent<EdgesProps, EdgesRef>;
|
package/core/Edges.js
CHANGED
|
@@ -5,6 +5,7 @@ import { Line } from './Line.js';
|
|
|
5
5
|
|
|
6
6
|
const Edges = /* @__PURE__ */React.forwardRef(({
|
|
7
7
|
threshold = 15,
|
|
8
|
+
geometry: explicitGeometry,
|
|
8
9
|
...props
|
|
9
10
|
}, fref) => {
|
|
10
11
|
const ref = React.useRef(null);
|
|
@@ -14,18 +15,17 @@ const Edges = /* @__PURE__ */React.forwardRef(({
|
|
|
14
15
|
const memoizedThreshold = React.useRef();
|
|
15
16
|
React.useLayoutEffect(() => {
|
|
16
17
|
const parent = ref.current.parent;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
18
|
+
const geometry = explicitGeometry !== null && explicitGeometry !== void 0 ? explicitGeometry : parent == null ? void 0 : parent.geometry;
|
|
19
|
+
if (!geometry) return;
|
|
20
|
+
const cached = memoizedGeometry.current === geometry && memoizedThreshold.current === threshold;
|
|
21
|
+
if (cached) return;
|
|
22
|
+
memoizedGeometry.current = geometry;
|
|
23
|
+
memoizedThreshold.current = threshold;
|
|
24
|
+
const points = new THREE.EdgesGeometry(geometry, threshold).attributes.position.array;
|
|
25
|
+
ref.current.geometry.setPositions(points);
|
|
26
|
+
ref.current.geometry.attributes.instanceStart.needsUpdate = true;
|
|
27
|
+
ref.current.geometry.attributes.instanceEnd.needsUpdate = true;
|
|
28
|
+
ref.current.computeLineDistances();
|
|
29
29
|
});
|
|
30
30
|
return /*#__PURE__*/React.createElement(Line, _extends({
|
|
31
31
|
segments: true,
|
package/core/Fbo.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ type FBOSettings = {
|
|
|
21
21
|
};
|
|
22
22
|
export declare function useFBO(width?: number | FBOSettings, height?: number, settings?: FBOSettings): THREE.WebGLRenderTarget;
|
|
23
23
|
export declare const Fbo: ({ children, width, height, ...settings }: {
|
|
24
|
-
children?: (
|
|
24
|
+
children?: (target: ReturnType<typeof useFBO>) => React.ReactNode;
|
|
25
25
|
width: Parameters<typeof useFBO>[0];
|
|
26
26
|
height: Parameters<typeof useFBO>[1];
|
|
27
27
|
} & FBOSettings) => React.JSX.Element;
|
package/core/Ktx2.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare namespace useKTX2 {
|
|
|
8
8
|
var clear: (input: string | string[]) => void;
|
|
9
9
|
}
|
|
10
10
|
export declare const Ktx2: ({ children, input, basisPath, }: {
|
|
11
|
-
children?: (
|
|
11
|
+
children?: (texture: ReturnType<typeof useKTX2>) => React.ReactNode;
|
|
12
12
|
input: Parameters<typeof useKTX2>[0];
|
|
13
13
|
basisPath?: Parameters<typeof useKTX2>[1];
|
|
14
14
|
}) => React.JSX.Element;
|
package/core/MatcapTexture.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import { Texture } from 'three';
|
|
3
3
|
export declare function useMatcapTexture(id?: number | string, format?: number, onLoad?: (texture: Texture | Texture[]) => void): [Texture, string, number];
|
|
4
4
|
export declare const MatcapTexture: ({ children, id, format, onLoad, }: {
|
|
5
|
-
children?: (
|
|
5
|
+
children?: (texture: ReturnType<typeof useMatcapTexture>) => React.ReactNode;
|
|
6
6
|
id?: Parameters<typeof useMatcapTexture>[0];
|
|
7
7
|
format?: Parameters<typeof useMatcapTexture>[1];
|
|
8
8
|
onLoad?: Parameters<typeof useMatcapTexture>[2];
|
package/core/NormalTexture.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ type Settings = {
|
|
|
7
7
|
};
|
|
8
8
|
export declare function useNormalTexture(id?: number, settings?: Settings, onLoad?: (texture: Texture | Texture[]) => void): [Texture, string, number];
|
|
9
9
|
export declare const NormalTexture: ({ children, id, onLoad, ...settings }: {
|
|
10
|
-
children?: (
|
|
10
|
+
children?: (texture: ReturnType<typeof useNormalTexture>) => React.ReactNode;
|
|
11
11
|
id?: Parameters<typeof useNormalTexture>[0];
|
|
12
12
|
onLoad?: Parameters<typeof useNormalTexture>[2];
|
|
13
13
|
} & Settings) => React.JSX.Element;
|
package/core/Texture.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export declare namespace useTexture {
|
|
|
13
13
|
var clear: (input: string | string[]) => void;
|
|
14
14
|
}
|
|
15
15
|
export declare const Texture: ({ children, input, onLoad, }: {
|
|
16
|
-
children?: (
|
|
16
|
+
children?: (texture: ReturnType<typeof useTexture>) => React.ReactNode;
|
|
17
17
|
input: Parameters<typeof useTexture>[0];
|
|
18
18
|
onLoad?: Parameters<typeof useTexture>[1];
|
|
19
19
|
}) => React.JSX.Element;
|
package/core/TrailTexture.d.ts
CHANGED
|
@@ -13,6 +13,6 @@ type TrailConfig = {
|
|
|
13
13
|
};
|
|
14
14
|
export declare function useTrailTexture(config?: Partial<TrailConfig>): [Texture, (ThreeEvent: any) => void];
|
|
15
15
|
export declare const TrailTexture: ({ children, ...config }: {
|
|
16
|
-
children?: (
|
|
16
|
+
children?: (texture: ReturnType<typeof useTrailTexture>) => React.ReactNode;
|
|
17
17
|
} & TrailConfig) => React.JSX.Element;
|
|
18
18
|
export {};
|
package/core/VideoTexture.d.ts
CHANGED
|
@@ -8,11 +8,7 @@ type Config = {
|
|
|
8
8
|
} & Partial<Omit<HTMLVideoElement, 'children'>>;
|
|
9
9
|
export declare function useVideoTexture(src: string | MediaStream, { unsuspend, start, crossOrigin, muted, loop, hls, ...videoProps }?: Config): THREE.VideoTexture;
|
|
10
10
|
export declare const VideoTexture: ({ children, src, ...config }: {
|
|
11
|
-
children?: (
|
|
11
|
+
children?: (texture: ReturnType<typeof useVideoTexture>) => React.ReactNode;
|
|
12
12
|
src: Parameters<typeof useVideoTexture>[0];
|
|
13
|
-
} &
|
|
14
|
-
unsuspend?: "canplay" | "canplaythrough" | "loadedmetadata" | "loadstart" | undefined;
|
|
15
|
-
start?: boolean | undefined;
|
|
16
|
-
hls?: Partial<HlsConfig> | undefined;
|
|
17
|
-
} & Partial<Omit<HTMLVideoElement, "children">>) => React.JSX.Element;
|
|
13
|
+
} & Parameters<typeof useVideoTexture>[1]) => React.JSX.Element;
|
|
18
14
|
export {};
|
package/core/useEnvironment.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Texture, Loader
|
|
1
|
+
import { Texture, Loader } from 'three';
|
|
2
2
|
import { PresetsType } from '../helpers/environment-assets';
|
|
3
3
|
import { TextureEncoding } from '../helpers/deprecated';
|
|
4
4
|
export type EnvironmentLoaderProps = {
|
|
@@ -8,4 +8,4 @@ export type EnvironmentLoaderProps = {
|
|
|
8
8
|
extensions?: (loader: Loader) => void;
|
|
9
9
|
encoding?: TextureEncoding;
|
|
10
10
|
};
|
|
11
|
-
export declare function useEnvironment({ files, path, preset, encoding, extensions, }?: Partial<EnvironmentLoaderProps>): Texture
|
|
11
|
+
export declare function useEnvironment({ files, path, preset, encoding, extensions, }?: Partial<EnvironmentLoaderProps>): Texture;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),r=require("@react-three/fiber"),t=require("react");function o(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),r=require("@react-three/fiber"),t=require("react");function o(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}var a=o(e),n=o(t);const s=e=>{if(Array.isArray(e))return e[0];if("object"==typeof e&&null!==e){return e[Object.keys(e)[0]][0]}return{w:0,h:0}},i=e=>{for(let r=3;r<e.length;r+=4)if(0!==e[r])return!1;return!0},u=(e,r,t,o)=>{const n=r*(o.aspect>e/r?o.width/e:o.height/r),s=e*(o.aspect>e/r?o.width/e:o.height/r)*t,i=n*t;let u=Math.min(1,s),c=Math.min(1,i);return s>1&&(u=1,c=i/s*1),new a.Vector3(u,c,1)};function c(o,c,f,l,m){const h=r.useThree((e=>e.viewport)),d=n.useRef(null),w=n.useRef(0),[p,g]=t.useState(null),[y,x]=n.useState(new a.Texture),S=new a.TextureLoader,[L,b]=t.useState(null);function j(e){(e||o)&&new Promise((r=>{S.load(null!=e?e:o,r)})).then((e=>{O(null,e)}))}function v(e,r,t){const o=fetch(e).then((e=>e.json())),a=new Promise((e=>{S.load(r,e)}));Promise.all([o,a]).then((e=>{t(e[0],e[1])}))}n.useLayoutEffect((()=>(c&&o?v(c,o,O):o&&j(),()=>{o&&r.useLoader.clear(e.TextureLoader,o)})),[]);const O=(e,r)=>{let t=new a.Vector3(1,1,1);if(null===e){if(r&&l){const e=r.image.width,o=r.image.height;w.current=l;const{rows:a,columns:n,frameWidth:s,frameHeight:i,emptyFrames:c}=z(r,l);d.current={frames:[],meta:{version:"1.0",size:{w:e,h:o},rows:a,columns:n,frameWidth:s,frameHeight:i,scale:"1"}};for(let e=0;e<a;e++)for(let r=0;r<n;r++){(null!=c?c:[]).some((t=>t.row===e&&t.col===r))||d.current.frames.push({frame:{x:r*s,y:e*i,w:s,h:i},rotated:!1,trimmed:!1,spriteSourceSize:{x:0,y:0,w:s,h:i},sourceSize:{w:s,h:i}})}t=u(s,i,.1,h)}d.current.frames=M(d.current.frames)}else if(r){d.current=e,d.current.frames=A(),w.current=Array.isArray(e.frames)?e.frames.length:Object.keys(e.frames).length;const{w:r,h:o}=s(e.frames).sourceSize;t=u(r,o,.1,h)}g(d.current),"encoding"in r?r.encoding=3001:r.colorSpace=a.SRGBColorSpace,x(r),b({spriteTexture:r,spriteData:d.current,aspect:t})},z=(e,r)=>{if(e.image){const t=document.createElement("canvas"),o=t.getContext("2d");t.width=e.image.width,t.height=e.image.height,o.drawImage(e.image,0,0);const a=e.image.width,n=e.image.height,s=Math.round(Math.sqrt(r*(a/n))),u=Math.round(r/s),c=a/s,f=n/u,l=[];for(let e=0;e<u;e++)for(let t=0;t<s;t++){if(e*s+t>=r){l.push({row:e,col:t});continue}const a=o.getImageData(t*c,e*f,c,f).data;i(a)&&l.push({row:e,col:t})}return{rows:u,columns:s,frameWidth:c,frameHeight:f,emptyFrames:l}}return{rows:0,columns:0,frameWidth:0,frameHeight:0,emptyFrames:[]}},A=()=>{const e={},r=d.current,t=f;if(t&&Array.isArray(r.frames)){for(let o=0;o<t.length;o++){e[t[o]]=[];for(const a of r.frames){const r=a.frame,n=r.x,s=r.y,i=r.w,u=r.h,c=a.sourceSize.w,f=a.sourceSize.h;"string"==typeof a.filename&&-1!==a.filename.toLowerCase().indexOf(t[o].toLowerCase())&&e[t[o]].push({x:n,y:s,w:i,h:u,frame:r,sourceSize:{w:c,h:f}})}}for(const r in e)e[r].frame=M(e[r]);return e}if(t&&"object"==typeof r.frames){for(let o=0;o<t.length;o++){e[t[o]]=[];for(const a in r.frames){const n=r.frames[a],s=n.frame,i=s.x,u=s.y,c=s.w,f=s.h,l=n.sourceSize.w,m=n.sourceSize.h;"string"==typeof a&&-1!==a.toLowerCase().indexOf(t[o].toLowerCase())&&e[t[o]].push({x:i,y:u,w:c,h:f,frame:s,sourceSize:{w:l,h:m}})}}for(const r in e)e[r].frame=M(e[r]);return e}{let e=[];for(const t in r.frames)e.push(r.frames[t]);return e=M(e),e}},M=e=>{let r=null;for(const t of e){const{w:e,h:o}=t.frame,a=e*o;(!r||a>r.area)&&(r={...t.frame,area:a})}for(const a of e){var t;const{w:e,h:n}=a.frame,s=e*n;var o;if(s===(null==(t=r)?void 0:t.area))a.scaleRatio=1;else a.scaleRatio=Math.sqrt(s/(null==(o=r)?void 0:o.area))}return e};return n.useLayoutEffect((()=>{null==m||m(y,p)}),[y,p]),{spriteObj:L,loadJsonAndTexture:function(e,r){r&&e?v(r,e,O):j(e)}}}c.preload=t=>r.useLoader.preload(e.TextureLoader,t),c.clear=t=>r.useLoader.clear(e.TextureLoader,t),exports.calculateAspectRatio=u,exports.checkIfFrameIsEmpty=i,exports.getFirstItem=s,exports.useSpriteLoader=c;
|
package/core/useSpriteLoader.js
CHANGED
|
@@ -155,6 +155,9 @@ function useSpriteLoader(input, json, animationNames, numberOfFrames, onLoad) {
|
|
|
155
155
|
}
|
|
156
156
|
aspect = calculateAspectRatio(frameWidth, frameHeight, aspectFactor, v);
|
|
157
157
|
}
|
|
158
|
+
|
|
159
|
+
//scale ratio for stadalone sprite
|
|
160
|
+
spriteDataRef.current.frames = calculateScaleRatio(spriteDataRef.current.frames);
|
|
158
161
|
} else if (_spriteTexture) {
|
|
159
162
|
spriteDataRef.current = json;
|
|
160
163
|
spriteDataRef.current.frames = parseFrames();
|
|
@@ -169,7 +172,7 @@ function useSpriteLoader(input, json, animationNames, numberOfFrames, onLoad) {
|
|
|
169
172
|
// @ts-ignore
|
|
170
173
|
if ('encoding' in _spriteTexture) _spriteTexture.encoding = 3001; // sRGBEncoding
|
|
171
174
|
// @ts-ignore
|
|
172
|
-
else _spriteTexture.colorSpace =
|
|
175
|
+
else _spriteTexture.colorSpace = THREE.SRGBColorSpace;
|
|
173
176
|
setSpriteTexture(_spriteTexture);
|
|
174
177
|
setSpriteObj({
|
|
175
178
|
spriteTexture: _spriteTexture,
|
|
@@ -263,6 +266,9 @@ function useSpriteLoader(input, json, animationNames, numberOfFrames, onLoad) {
|
|
|
263
266
|
}
|
|
264
267
|
}
|
|
265
268
|
}
|
|
269
|
+
for (const frame in sprites) {
|
|
270
|
+
sprites[frame].frame = calculateScaleRatio(sprites[frame]);
|
|
271
|
+
}
|
|
266
272
|
return sprites;
|
|
267
273
|
} else if (delimiters && typeof data['frames'] === 'object') {
|
|
268
274
|
for (let i = 0; i < delimiters.length; i++) {
|
|
@@ -292,16 +298,56 @@ function useSpriteLoader(input, json, animationNames, numberOfFrames, onLoad) {
|
|
|
292
298
|
}
|
|
293
299
|
}
|
|
294
300
|
}
|
|
301
|
+
for (const frame in sprites) {
|
|
302
|
+
sprites[frame].frame = calculateScaleRatio(sprites[frame]);
|
|
303
|
+
}
|
|
295
304
|
return sprites;
|
|
296
305
|
} else {
|
|
297
306
|
// we need to convert it into an array
|
|
298
|
-
|
|
307
|
+
let spritesArr = [];
|
|
299
308
|
for (const key in data.frames) {
|
|
300
309
|
spritesArr.push(data.frames[key]);
|
|
301
310
|
}
|
|
311
|
+
spritesArr = calculateScaleRatio(spritesArr);
|
|
302
312
|
return spritesArr;
|
|
303
313
|
}
|
|
304
314
|
};
|
|
315
|
+
|
|
316
|
+
// calculate scale ratio for the frames
|
|
317
|
+
const calculateScaleRatio = frames => {
|
|
318
|
+
// Find the largest frame
|
|
319
|
+
let largestFrame = null;
|
|
320
|
+
for (const frame of frames) {
|
|
321
|
+
const {
|
|
322
|
+
w,
|
|
323
|
+
h
|
|
324
|
+
} = frame.frame;
|
|
325
|
+
const area = w * h;
|
|
326
|
+
if (!largestFrame || area > largestFrame.area) {
|
|
327
|
+
largestFrame = {
|
|
328
|
+
...frame.frame,
|
|
329
|
+
area
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// Set scaleRatio property on each frame
|
|
335
|
+
for (const frame of frames) {
|
|
336
|
+
var _largestFrame;
|
|
337
|
+
const {
|
|
338
|
+
w,
|
|
339
|
+
h
|
|
340
|
+
} = frame.frame;
|
|
341
|
+
const area = w * h;
|
|
342
|
+
if (area === ((_largestFrame = largestFrame) == null ? void 0 : _largestFrame.area)) {
|
|
343
|
+
frame.scaleRatio = 1;
|
|
344
|
+
} else {
|
|
345
|
+
var _largestFrame2;
|
|
346
|
+
frame.scaleRatio = Math.sqrt(area / ((_largestFrame2 = largestFrame) == null ? void 0 : _largestFrame2.area));
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return frames;
|
|
350
|
+
};
|
|
305
351
|
React.useLayoutEffect(() => {
|
|
306
352
|
onLoad == null || onLoad(spriteTexture, spriteData);
|
|
307
353
|
}, [spriteTexture, spriteData]);
|