@react-three/drei 8.2.1 → 8.5.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.
- package/README.md +35 -1
- package/core/Cloud.cjs.js +1 -1
- package/core/Cloud.js +2 -2
- package/core/Edges.cjs.js +1 -0
- package/core/Edges.d.ts +8 -0
- package/core/Edges.js +35 -0
- package/core/GizmoViewcube.cjs.js +1 -1
- package/core/GizmoViewcube.js +1 -1
- package/core/Instances.cjs.js +1 -1
- package/core/Instances.d.ts +12 -24
- package/core/Instances.js +11 -23
- package/core/MeshReflectorMaterial.cjs.js +1 -1
- package/core/MeshReflectorMaterial.js +1 -1
- package/core/TransformControls.cjs.js +1 -1
- package/core/TransformControls.d.ts +2 -1
- package/core/TransformControls.js +2 -1
- package/core/index.cjs.js +1 -1
- package/core/index.d.ts +2 -0
- package/core/index.js +2 -3
- package/core/useKTX2.cjs.js +1 -0
- package/core/useKTX2.d.ts +8 -0
- package/core/useKTX2.js +39 -0
- package/core/useMatcapTexture.cjs.js +1 -1
- package/core/useMatcapTexture.js +7 -2
- package/core/useNormalTexture.cjs.js +1 -1
- package/core/useNormalTexture.js +8 -3
- package/helpers/Position.cjs.js +1 -1
- package/helpers/Position.d.ts +5 -0
- package/helpers/Position.js +51 -0
- package/index.cjs.js +1 -1
- package/index.js +2 -0
- package/native/index.cjs.js +1 -1
- package/native/index.js +2 -3
- package/package.json +1 -1
- package/web/PresentationControls.cjs.js +1 -1
- package/web/PresentationControls.d.ts +2 -1
- package/web/PresentationControls.js +5 -4
- package/web/index.cjs.js +1 -1
- package/web/index.js +2 -3
- package/assets/cloud.base64.cjs.js +0 -1
- package/assets/cloud.base64.d.ts +0 -1
- package/assets/cloud.base64.js +0 -3
- package/helpers/matcap-assets.cjs.js +0 -1
- package/helpers/matcap-assets.d.ts +0 -643
- package/helpers/matcap-assets.js +0 -645
- package/helpers/normal-assets.cjs.js +0 -1
- package/helpers/normal-assets.d.ts +0 -78
- package/helpers/normal-assets.js +0 -80
package/core/useMatcapTexture.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useTexture } from './useTexture.js';
|
|
3
|
-
import {
|
|
3
|
+
import { useAsset } from 'use-asset';
|
|
4
4
|
|
|
5
5
|
function getFormatString(format) {
|
|
6
6
|
switch (format) {
|
|
@@ -21,9 +21,14 @@ function getFormatString(format) {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
const LIST_URL = 'https://cdn.jsdelivr.net/gh/pmndrs/drei-assets@master/matcaps.json';
|
|
24
25
|
const MATCAP_ROOT = 'https://rawcdn.githack.com/emmelleppi/matcaps/9b36ccaaf0a24881a39062d05566c9e92be4aa0d';
|
|
25
|
-
const DEFAULT_MATCAP = matcapList[0];
|
|
26
26
|
function useMatcapTexture(id = 0, format = 1024) {
|
|
27
|
+
const matcapList = useAsset(() => new Promise(async resolve => {
|
|
28
|
+
const matcapList = await fetch(LIST_URL).then(res => res.json());
|
|
29
|
+
resolve(matcapList);
|
|
30
|
+
}), 'matcapList');
|
|
31
|
+
const DEFAULT_MATCAP = matcapList[0];
|
|
27
32
|
const numTot = React.useMemo(() => Object.keys(matcapList).length, []);
|
|
28
33
|
const fileHash = React.useMemo(() => {
|
|
29
34
|
if (typeof id === 'string') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("./useTexture.cjs.js"),t=require("three"),s=require("
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("./useTexture.cjs.js"),t=require("three"),s=require("use-asset");function n(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var s=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,s.get?s:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}require("@react-three/fiber");var a=n(e);exports.useNormalTexture=function(e=0,n={}){const{repeat:o=[1,1],anisotropy:u=1,offset:c=[0,0]}=n,i=s.useAsset((()=>new Promise((async e=>{e(await fetch("https://cdn.jsdelivr.net/gh/pmndrs/drei-assets@master/normals/normals.json").then((e=>e.json())))}))),"normalsList"),f=a.useMemo((()=>Object.keys(i).length),[]),p=i[0],l=`https://rawcdn.githack.com/pmndrs/drei-assets/7a3104997e1576f83472829815b00880d88b32fb/normals/${i[e]||p}`,d=r.useTexture(l);return a.useLayoutEffect((()=>{d&&(d.wrapS=d.wrapT=t.RepeatWrapping,d.repeat=new t.Vector2(o[0],o[1]),d.offset=new t.Vector2(c[0],c[1]),d.anisotropy=u)}),[d,u,o,c]),[d,l,f]};
|
package/core/useNormalTexture.js
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useTexture } from './useTexture.js';
|
|
3
3
|
import { RepeatWrapping, Vector2 } from 'three';
|
|
4
|
-
import {
|
|
4
|
+
import { useAsset } from 'use-asset';
|
|
5
5
|
|
|
6
|
-
const NORMAL_ROOT = 'https://rawcdn.githack.com/
|
|
7
|
-
const
|
|
6
|
+
const NORMAL_ROOT = 'https://rawcdn.githack.com/pmndrs/drei-assets/7a3104997e1576f83472829815b00880d88b32fb';
|
|
7
|
+
const LIST_URL = 'https://cdn.jsdelivr.net/gh/pmndrs/drei-assets@master/normals/normals.json';
|
|
8
8
|
function useNormalTexture(id = 0, settings = {}) {
|
|
9
9
|
const {
|
|
10
10
|
repeat = [1, 1],
|
|
11
11
|
anisotropy = 1,
|
|
12
12
|
offset = [0, 0]
|
|
13
13
|
} = settings;
|
|
14
|
+
const normalsList = useAsset(() => new Promise(async resolve => {
|
|
15
|
+
const normalsList = await fetch(LIST_URL).then(res => res.json());
|
|
16
|
+
resolve(normalsList);
|
|
17
|
+
}), 'normalsList');
|
|
14
18
|
const numTot = React.useMemo(() => Object.keys(normalsList).length, []);
|
|
19
|
+
const DEFAULT_NORMAL = normalsList[0];
|
|
15
20
|
const imageName = normalsList[id] || DEFAULT_NORMAL;
|
|
16
21
|
const url = `${NORMAL_ROOT}/normals/${imageName}`;
|
|
17
22
|
const normalTexture = useTexture(url);
|
package/helpers/Position.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function e(e){if(e&&e.__esModule)return e;var
|
|
1
|
+
"use strict";function e(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)}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("three"));const r=new t.Matrix4,n=new t.Matrix4,i=[],s=new t.Mesh;class o extends t.Group{constructor(){super(),this.color=new t.Color("white"),this.instance={current:void 0},this.instanceKey={current:void 0}}get geometry(){var e;return null==(e=this.instance.current)?void 0:e.geometry}raycast(e,t){const o=this.instance.current;if(!o)return;if(!o.geometry||!o.material)return;s.geometry=o.geometry;const c=o.matrixWorld;let a=o.userData.instances.indexOf(this.instanceKey);if(-1!==a){o.getMatrixAt(a,r),n.multiplyMatrices(c,r),s.matrixWorld=n,s.raycast(e,i);for(let e=0,r=i.length;e<r;e++){const r=i[e];r.instanceId=a,r.object=this,t.push(r)}i.length=0}}}exports.Position=o;
|
package/helpers/Position.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import * as THREE from 'three';
|
|
2
3
|
import { ReactThreeFiber } from '@react-three/fiber';
|
|
3
4
|
declare global {
|
|
@@ -9,5 +10,9 @@ declare global {
|
|
|
9
10
|
}
|
|
10
11
|
export declare class Position extends THREE.Group {
|
|
11
12
|
color: THREE.Color;
|
|
13
|
+
instance: React.MutableRefObject<THREE.InstancedMesh | undefined>;
|
|
14
|
+
instanceKey: React.MutableRefObject<JSX.IntrinsicElements['position'] | undefined>;
|
|
12
15
|
constructor();
|
|
16
|
+
get geometry(): THREE.BufferGeometry | undefined;
|
|
17
|
+
raycast(raycaster: any, intersects: any): void;
|
|
13
18
|
}
|
package/helpers/Position.js
CHANGED
|
@@ -1,9 +1,60 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
|
|
3
|
+
const _instanceLocalMatrix = /*@__PURE__*/new THREE.Matrix4();
|
|
4
|
+
|
|
5
|
+
const _instanceWorldMatrix = /*@__PURE__*/new THREE.Matrix4();
|
|
6
|
+
|
|
7
|
+
const _instanceIntersects = [];
|
|
8
|
+
|
|
9
|
+
const _mesh = /*@__PURE__*/new THREE.Mesh();
|
|
10
|
+
|
|
3
11
|
class Position extends THREE.Group {
|
|
4
12
|
constructor() {
|
|
5
13
|
super();
|
|
6
14
|
this.color = new THREE.Color('white');
|
|
15
|
+
this.instance = {
|
|
16
|
+
current: undefined
|
|
17
|
+
};
|
|
18
|
+
this.instanceKey = {
|
|
19
|
+
current: undefined
|
|
20
|
+
};
|
|
21
|
+
} // This will allow the virtual instance have bounds
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
get geometry() {
|
|
25
|
+
var _this$instance$curren;
|
|
26
|
+
|
|
27
|
+
return (_this$instance$curren = this.instance.current) == null ? void 0 : _this$instance$curren.geometry;
|
|
28
|
+
} // And this will allow the virtual instance to receive events
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
raycast(raycaster, intersects) {
|
|
32
|
+
const parent = this.instance.current;
|
|
33
|
+
if (!parent) return;
|
|
34
|
+
if (!parent.geometry || !parent.material) return;
|
|
35
|
+
_mesh.geometry = parent.geometry;
|
|
36
|
+
const matrixWorld = parent.matrixWorld;
|
|
37
|
+
let instanceId = parent.userData.instances.indexOf(this.instanceKey);
|
|
38
|
+
if (instanceId === -1) return; // calculate the world matrix for each instance
|
|
39
|
+
|
|
40
|
+
parent.getMatrixAt(instanceId, _instanceLocalMatrix);
|
|
41
|
+
|
|
42
|
+
_instanceWorldMatrix.multiplyMatrices(matrixWorld, _instanceLocalMatrix); // the mesh represents this single instance
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
_mesh.matrixWorld = _instanceWorldMatrix;
|
|
46
|
+
|
|
47
|
+
_mesh.raycast(raycaster, _instanceIntersects); // process the result of raycast
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
for (let i = 0, l = _instanceIntersects.length; i < l; i++) {
|
|
51
|
+
const intersect = _instanceIntersects[i];
|
|
52
|
+
intersect.instanceId = instanceId;
|
|
53
|
+
intersect.object = this;
|
|
54
|
+
intersects.push(intersect);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
_instanceIntersects.length = 0;
|
|
7
58
|
}
|
|
8
59
|
|
|
9
60
|
}
|