@react-three/drei 9.117.1 → 9.117.3

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/core/Decal.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"),o=require("@react-three/fiber"),n=require("three-stdlib");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function i(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var s=a(e),l=i(t),c=i(r);function u(e=[0,0,0]){return function(e){return Array.isArray(e)}(e)?e:e instanceof c.Vector3||e instanceof c.Euler?[e.x,e.y,e.z]:[e,e,e]}const p=l.forwardRef((function({debug:e,depthTest:t=!1,polygonOffsetFactor:r=-10,map:a,mesh:i,children:p,position:f,rotation:m,scale:y,...d},b){const h=l.useRef(null);l.useImperativeHandle(b,(()=>h.current));const g=l.useRef(null);return l.useLayoutEffect((()=>{const e=(null==i?void 0:i.current)||h.current.parent,t=h.current;if(!(e instanceof c.Mesh))throw new Error('Decal must have a Mesh as parent or specify its "mesh" prop');const r={position:new c.Vector3,rotation:new c.Euler,scale:new c.Vector3(1,1,1)};if(e){o.applyProps(r,{position:f,scale:y});const a=e.matrixWorld.clone();if(e.matrixWorld.identity(),m&&"number"!=typeof m)o.applyProps(r,{rotation:m});else{const t=new c.Object3D;t.position.copy(r.position);const n=e.geometry.attributes.position.array;void 0===e.geometry.attributes.normal&&e.geometry.computeVertexNormals();const a=e.geometry.attributes.normal.array;let i=1/0;new c.Vector3;let s=new c.Vector3;const l=t.position.x,u=t.position.y,p=t.position.z,f=n.length;let y=-1;for(let e=0;e<f;e+=3){const t=n[e]-l,r=n[e+1]-u,o=n[e+2]-p,a=t*t+r*r+o*o;a<i&&(i=a,y=e)}s.fromArray(a,y),t.lookAt(t.position.clone().add(s)),t.rotateZ(Math.PI),t.rotateY(Math.PI),"number"==typeof m&&t.rotateZ(m),o.applyProps(r,{rotation:t.rotation})}return t.geometry=new n.DecalGeometry(e,r.position,r.rotation,r.scale),g.current&&(o.applyProps(g.current,r),g.current.traverse((e=>e.raycast=()=>null))),e.matrixWorld=a,()=>{t.geometry.dispose()}}}),[i,e,...u(f),...u(y),...u(m)]),l.createElement("mesh",s.default({ref:h,"material-transparent":!0,"material-polygonOffset":!0,"material-polygonOffsetFactor":r,"material-depthTest":t,"material-map":a},d),p,e&&l.createElement("mesh",{ref:g},l.createElement("boxGeometry",null),l.createElement("meshNormalMaterial",{wireframe:!0}),l.createElement("axesHelper",null)))}));exports.Decal=p;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),t=require("react"),r=require("three"),o=require("@react-three/fiber"),n=require("three-stdlib");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function i(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var c=a(e),s=i(t),l=i(r);function u(e=[0,0,0]){return function(e){return Array.isArray(e)}(e)?e:e instanceof l.Vector3||e instanceof l.Euler?[e.x,e.y,e.z]:[e,e,e]}const p=s.forwardRef((function({debug:e,depthTest:t=!1,polygonOffsetFactor:r=-10,map:a,mesh:i,children:p,position:f,rotation:m,scale:y,...d},b){const h=s.useRef(null);s.useImperativeHandle(b,(()=>h.current));const g=s.useRef(null),w=s.useRef({position:new l.Vector3,rotation:new l.Euler,scale:new l.Vector3(1,1,1)});return s.useLayoutEffect((()=>{const e=(null==i?void 0:i.current)||h.current.parent,t=h.current;if(!(e instanceof l.Mesh))throw new Error('Decal must have a Mesh as parent or specify its "mesh" prop');if(e){o.applyProps(w.current,{position:f,scale:y});const r=e.matrixWorld.clone();if(e.matrixWorld.identity(),m&&"number"!=typeof m)o.applyProps(w.current,{rotation:m});else{const t=new l.Object3D;t.position.copy(w.current.position);const r=e.geometry.attributes.position.array;void 0===e.geometry.attributes.normal&&e.geometry.computeVertexNormals();const n=e.geometry.attributes.normal.array;let a=1/0;new l.Vector3;let i=new l.Vector3;const c=t.position.x,s=t.position.y,u=t.position.z,p=r.length;let f=-1;for(let e=0;e<p;e+=3){const t=r[e]-c,o=r[e+1]-s,n=r[e+2]-u,i=t*t+o*o+n*n;i<a&&(a=i,f=e)}i.fromArray(n,f),t.lookAt(t.position.clone().add(i)),t.rotateZ(Math.PI),t.rotateY(Math.PI),"number"==typeof m&&t.rotateZ(m),o.applyProps(w.current,{rotation:t.rotation})}return t.geometry=new n.DecalGeometry(e,w.current.position,w.current.rotation,w.current.scale),e.matrixWorld=r,()=>{t.geometry.dispose()}}}),[i,...u(f),...u(y),...u(m)]),s.useLayoutEffect((()=>{g.current&&(o.applyProps(g.current,w.current),g.current.traverse((e=>e.raycast=()=>null)))}),[e]),s.createElement("mesh",c.default({ref:h,"material-transparent":!0,"material-polygonOffset":!0,"material-polygonOffsetFactor":r,"material-depthTest":t,"material-map":a},d),p,e&&s.createElement("mesh",{ref:g},s.createElement("boxGeometry",null),s.createElement("meshNormalMaterial",{wireframe:!0}),s.createElement("axesHelper",null)))}));exports.Decal=p;
package/core/Decal.js CHANGED
@@ -31,19 +31,19 @@ const Decal = /* @__PURE__ */React.forwardRef(function Decal({
31
31
  const ref = React.useRef(null);
32
32
  React.useImperativeHandle(forwardRef, () => ref.current);
33
33
  const helper = React.useRef(null);
34
+ const state = React.useRef({
35
+ position: new THREE.Vector3(),
36
+ rotation: new THREE.Euler(),
37
+ scale: new THREE.Vector3(1, 1, 1)
38
+ });
34
39
  React.useLayoutEffect(() => {
35
40
  const parent = (mesh == null ? void 0 : mesh.current) || ref.current.parent;
36
41
  const target = ref.current;
37
42
  if (!(parent instanceof THREE.Mesh)) {
38
43
  throw new Error('Decal must have a Mesh as parent or specify its "mesh" prop');
39
44
  }
40
- const state = {
41
- position: new THREE.Vector3(),
42
- rotation: new THREE.Euler(),
43
- scale: new THREE.Vector3(1, 1, 1)
44
- };
45
45
  if (parent) {
46
- applyProps(state, {
46
+ applyProps(state.current, {
47
47
  position,
48
48
  scale
49
49
  });
@@ -53,7 +53,7 @@ const Decal = /* @__PURE__ */React.forwardRef(function Decal({
53
53
  parent.matrixWorld.identity();
54
54
  if (!rotation || typeof rotation === 'number') {
55
55
  const o = new THREE.Object3D();
56
- o.position.copy(state.position);
56
+ o.position.copy(state.current.position);
57
57
 
58
58
  // Thanks https://x.com/N8Programs !
59
59
  const vertices = parent.geometry.attributes.position.array;
@@ -87,27 +87,29 @@ const Decal = /* @__PURE__ */React.forwardRef(function Decal({
87
87
  o.rotateZ(Math.PI);
88
88
  o.rotateY(Math.PI);
89
89
  if (typeof rotation === 'number') o.rotateZ(rotation);
90
- applyProps(state, {
90
+ applyProps(state.current, {
91
91
  rotation: o.rotation
92
92
  });
93
93
  } else {
94
- applyProps(state, {
94
+ applyProps(state.current, {
95
95
  rotation
96
96
  });
97
97
  }
98
- target.geometry = new DecalGeometry(parent, state.position, state.rotation, state.scale);
99
- if (helper.current) {
100
- applyProps(helper.current, state);
101
- // Prevent the helpers from blocking rays
102
- helper.current.traverse(child => child.raycast = () => null);
103
- }
98
+ target.geometry = new DecalGeometry(parent, state.current.position, state.current.rotation, state.current.scale);
104
99
  // Reset parents matix-world
105
100
  parent.matrixWorld = matrixWorld;
106
101
  return () => {
107
102
  target.geometry.dispose();
108
103
  };
109
104
  }
110
- }, [mesh, debug, ...vecToArray(position), ...vecToArray(scale), ...vecToArray(rotation)]);
105
+ }, [mesh, ...vecToArray(position), ...vecToArray(scale), ...vecToArray(rotation)]);
106
+ React.useLayoutEffect(() => {
107
+ if (helper.current) {
108
+ applyProps(helper.current, state.current);
109
+ // Prevent the helpers from blocking rays
110
+ helper.current.traverse(child => child.raycast = () => null);
111
+ }
112
+ }, [debug]);
111
113
 
112
114
  // <meshStandardMaterial transparent polygonOffset polygonOffsetFactor={-10} {...props} />}
113
115
  return /*#__PURE__*/React.createElement("mesh", _extends({
package/core/Text3D.d.ts CHANGED
@@ -2,7 +2,7 @@ import * as React from 'react';
2
2
  import * as THREE from 'three';
3
3
  import { MeshProps, Node } from '@react-three/fiber';
4
4
  import { TextGeometryParameters } from 'three-stdlib';
5
- import { useFont } from './useFont';
5
+ import { FontData } from './useFont';
6
6
  import { ForwardRefComponent } from '../helpers/ts-utils';
7
7
  declare global {
8
8
  namespace JSX {
@@ -12,7 +12,7 @@ declare global {
12
12
  }
13
13
  }
14
14
  type Text3DProps = {
15
- font: Parameters<typeof useFont>[0];
15
+ font: FontData | string;
16
16
  bevelSegments?: number;
17
17
  smooth?: number;
18
18
  } & Omit<TextGeometryParameters, 'font'> & MeshProps;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three-stdlib"),r=require("suspend-react");let n=null,t=null;async function a(r){if("string"==typeof r){var n;const u=await fetch(r);if(null!=(n=u.headers.get("Content-Type"))&&n.includes("application/json"))return await u.json();{const r=await u.arrayBuffer();return a=r,t||(t=new e.TTFLoader),t.parse(a)}}return r;var a}async function u(r){return function(r){return n||(n=new e.FontLoader),n.parse(r)}(await a(r))}function s(e){return r.suspend(u,[e])}s.preload=e=>r.preload(u,[e]),s.clear=e=>r.clear([e]),exports.useFont=s;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three-stdlib"),r=require("suspend-react");let t=null;async function n(r){const n=await async function(e){return"string"==typeof e?await(await fetch(e)).json():e}(r);return a=n,t||(t=new e.FontLoader),t.parse(a);var a}function a(e){return r.suspend(n,[e])}a.preload=e=>r.preload(n,[e]),a.clear=e=>r.clear([e]),exports.useFont=a;
package/core/useFont.js CHANGED
@@ -1,37 +1,19 @@
1
- import { FontLoader, TTFLoader } from 'three-stdlib';
1
+ import { FontLoader } from 'three-stdlib';
2
2
  import { suspend, preload, clear } from 'suspend-react';
3
3
 
4
4
  let fontLoader = null;
5
- let ttfLoader = null;
5
+ async function loadFontData(font) {
6
+ return typeof font === 'string' ? await (await fetch(font)).json() : font;
7
+ }
6
8
  function parseFontData(fontData) {
7
9
  if (!fontLoader) {
8
10
  fontLoader = new FontLoader();
9
11
  }
10
12
  return fontLoader.parse(fontData);
11
13
  }
12
- function parseTtfArrayBuffer(ttfData) {
13
- if (!ttfLoader) {
14
- ttfLoader = new TTFLoader();
15
- }
16
- return ttfLoader.parse(ttfData);
17
- }
18
- async function loadFontData(font) {
19
- if (typeof font === 'string') {
20
- var _res$headers$get;
21
- const res = await fetch(font);
22
- if ((_res$headers$get = res.headers.get('Content-Type')) != null && _res$headers$get.includes('application/json')) {
23
- return await res.json();
24
- } else {
25
- const arrayBuffer = await res.arrayBuffer();
26
- return parseTtfArrayBuffer(arrayBuffer);
27
- }
28
- } else {
29
- return font;
30
- }
31
- }
32
14
  async function loader(font) {
33
- const fontData = await loadFontData(font);
34
- return parseFontData(fontData);
15
+ const data = await loadFontData(font);
16
+ return parseFontData(data);
35
17
  }
36
18
  function useFont(font) {
37
19
  return suspend(loader, [font]);