@react-three/drei 9.83.0 → 9.83.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 +1 -1
- package/core/Outlines.cjs.js +1 -1
- package/core/Outlines.d.ts +10 -8
- package/core/Outlines.js +24 -12
- 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
|
@@ -1403,7 +1403,7 @@ Abstracts [THREE.EdgesGeometry](https://threejs.org/docs/#api/en/geometries/Edge
|
|
|
1403
1403
|
<a href="https://codesandbox.io/s/2gh6jf"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/2gh6jf/screenshot.png" alt="Demo"/></a>
|
|
1404
1404
|
</p>
|
|
1405
1405
|
|
|
1406
|
-
An ornamental component that extracts the geometry from its parent and displays an [inverted-hull outline](https://bnpr.gitbook.io/bnpr/outline/inverse-hull-method).
|
|
1406
|
+
An ornamental component that extracts the geometry from its parent and displays an [inverted-hull outline](https://bnpr.gitbook.io/bnpr/outline/inverse-hull-method). Supported parents are `<mesh>`, `<skinnedMesh>` and `<instancedMesh>`.
|
|
1407
1407
|
|
|
1408
1408
|
```tsx
|
|
1409
1409
|
type OutlinesProps = JSX.IntrinsicElements['group'] & {
|
package/core/Outlines.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),n=require("three"),r=require("react"),t=require("./shaderMaterial.cjs.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),n=require("three"),r=require("react"),t=require("./shaderMaterial.cjs.js"),o=require("@react-three/fiber"),i=require("three-stdlib");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function c(e){if(e&&e.__esModule)return e;var n=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var t=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,t.get?t:{enumerable:!0,get:function(){return e[r]}})}})),n.default=e,Object.freeze(n)}var s=a(e),l=c(n),d=c(r);const u=t.shaderMaterial({color:new l.Color("black"),opacity:1,thickness:.05},"#include <common>\n #include <morphtarget_pars_vertex>\n #include <skinning_pars_vertex>\n uniform float thickness;\n void main() {\n #if defined (USE_SKINNING)\n\t #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinbase_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n #endif\n #include <begin_vertex>\n\t #include <morphtarget_vertex>\n\t #include <skinning_vertex>\n #include <project_vertex>\n vec4 transformedNormal = vec4(normal, 0.0);\n vec4 transformedPosition = vec4(transformed, 1.0);\n #ifdef USE_INSTANCING\n transformedNormal = instanceMatrix * transformedNormal;\n transformedPosition = instanceMatrix * transformedPosition;\n #endif\n vec3 newPosition = transformedPosition.xyz + transformedNormal.xyz * thickness;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(newPosition, 1.0); \n }",`uniform vec3 color;\n uniform float opacity;\n void main(){\n gl_FragColor = vec4(color, opacity);\n #include <tonemapping_fragment>\n #include <${parseInt(l.REVISION.replace(/\D+/g,""))>=154?"colorspace_fragment":"encodings_fragment"}>\n }`);exports.Outlines=function({color:e="black",opacity:n=1,transparent:r=!1,thickness:t=.05,angle:a=Math.PI,...c}){var f,m;const p=d.useRef(null),[g]=d.useState((()=>new u({side:l.BackSide})));return d.useMemo((()=>o.extend({OutlinesMaterial:u})),[]),d.useLayoutEffect((()=>{const e=p.current,n=e.parent;if(n&&n.geometry){let r;return n.skeleton?(r=new l.SkinnedMesh,r.material=g,r.bind(n.skeleton,n.bindMatrix),e.add(r)):n.isInstancedMesh?(r=new l.InstancedMesh(n.geometry,g,n.count),r.instanceMatrix=n.instanceMatrix,e.add(r)):(r=new l.Mesh,r.material=g,e.add(r)),r.geometry=a?i.toCreasedNormals(n.geometry,a):n.geometry,()=>{a&&r.geometry.dispose(),e.remove(r)}}}),[a,null==(f=p.current)||null==(m=f.parent)?void 0:m.geometry]),d.useLayoutEffect((()=>{const i=p.current;console.log(i.children.length);const a=i.children[0];a&&o.applyProps(a.material,{transparent:r,thickness:t,color:e,opacity:n})}),[a,r,t,e,n]),d.createElement("group",s.default({ref:p},c))};
|
package/core/Outlines.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
color
|
|
5
|
-
opacity
|
|
6
|
-
transparent
|
|
7
|
-
thickness
|
|
8
|
-
angle
|
|
9
|
-
}
|
|
2
|
+
import { ReactThreeFiber } from '@react-three/fiber';
|
|
3
|
+
declare type OutlinesProps = JSX.IntrinsicElements['group'] & {
|
|
4
|
+
color: ReactThreeFiber.Color;
|
|
5
|
+
opacity: number;
|
|
6
|
+
transparent: boolean;
|
|
7
|
+
thickness: number;
|
|
8
|
+
angle: number;
|
|
9
|
+
};
|
|
10
|
+
export declare function Outlines({ color, opacity, transparent, thickness, angle, ...props }: OutlinesProps): JSX.Element;
|
|
11
|
+
export {};
|
package/core/Outlines.js
CHANGED
|
@@ -2,7 +2,7 @@ import _extends from '@babel/runtime/helpers/esm/extends';
|
|
|
2
2
|
import * as THREE from 'three';
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { shaderMaterial } from './shaderMaterial.js';
|
|
5
|
-
import { extend,
|
|
5
|
+
import { extend, applyProps } from '@react-three/fiber';
|
|
6
6
|
import { toCreasedNormals } from 'three-stdlib';
|
|
7
7
|
|
|
8
8
|
const OutlinesMaterial = shaderMaterial({
|
|
@@ -15,7 +15,7 @@ const OutlinesMaterial = shaderMaterial({
|
|
|
15
15
|
uniform float thickness;
|
|
16
16
|
void main() {
|
|
17
17
|
#if defined (USE_SKINNING)
|
|
18
|
-
|
|
18
|
+
#include <beginnormal_vertex>
|
|
19
19
|
#include <morphnormal_vertex>
|
|
20
20
|
#include <skinbase_vertex>
|
|
21
21
|
#include <skinnormal_vertex>
|
|
@@ -25,7 +25,13 @@ const OutlinesMaterial = shaderMaterial({
|
|
|
25
25
|
#include <morphtarget_vertex>
|
|
26
26
|
#include <skinning_vertex>
|
|
27
27
|
#include <project_vertex>
|
|
28
|
-
|
|
28
|
+
vec4 transformedNormal = vec4(normal, 0.0);
|
|
29
|
+
vec4 transformedPosition = vec4(transformed, 1.0);
|
|
30
|
+
#ifdef USE_INSTANCING
|
|
31
|
+
transformedNormal = instanceMatrix * transformedNormal;
|
|
32
|
+
transformedPosition = instanceMatrix * transformedPosition;
|
|
33
|
+
#endif
|
|
34
|
+
vec3 newPosition = transformedPosition.xyz + transformedNormal.xyz * thickness;
|
|
29
35
|
gl_Position = projectionMatrix * modelViewMatrix * vec4(newPosition, 1.0);
|
|
30
36
|
}`, `uniform vec3 color;
|
|
31
37
|
uniform float opacity;
|
|
@@ -42,7 +48,12 @@ function Outlines({
|
|
|
42
48
|
angle = Math.PI,
|
|
43
49
|
...props
|
|
44
50
|
}) {
|
|
51
|
+
var _ref$current, _ref$current$parent;
|
|
52
|
+
|
|
45
53
|
const ref = React.useRef(null);
|
|
54
|
+
const [material] = React.useState(() => new OutlinesMaterial({
|
|
55
|
+
side: THREE.BackSide
|
|
56
|
+
}));
|
|
46
57
|
React.useMemo(() => extend({
|
|
47
58
|
OutlinesMaterial
|
|
48
59
|
}), []);
|
|
@@ -55,28 +66,29 @@ function Outlines({
|
|
|
55
66
|
|
|
56
67
|
if (parent.skeleton) {
|
|
57
68
|
mesh = new THREE.SkinnedMesh();
|
|
58
|
-
mesh.material =
|
|
59
|
-
side: THREE.BackSide
|
|
60
|
-
});
|
|
69
|
+
mesh.material = material;
|
|
61
70
|
mesh.bind(parent.skeleton, parent.bindMatrix);
|
|
62
71
|
group.add(mesh);
|
|
72
|
+
} else if (parent.isInstancedMesh) {
|
|
73
|
+
mesh = new THREE.InstancedMesh(parent.geometry, material, parent.count);
|
|
74
|
+
mesh.instanceMatrix = parent.instanceMatrix;
|
|
75
|
+
group.add(mesh);
|
|
63
76
|
} else {
|
|
64
77
|
mesh = new THREE.Mesh();
|
|
65
|
-
mesh.material =
|
|
66
|
-
side: THREE.BackSide
|
|
67
|
-
});
|
|
78
|
+
mesh.material = material;
|
|
68
79
|
group.add(mesh);
|
|
69
80
|
}
|
|
70
81
|
|
|
71
82
|
mesh.geometry = angle ? toCreasedNormals(parent.geometry, angle) : parent.geometry;
|
|
72
83
|
return () => {
|
|
73
|
-
dispose(
|
|
74
|
-
group.
|
|
84
|
+
if (angle) mesh.geometry.dispose();
|
|
85
|
+
group.remove(mesh);
|
|
75
86
|
};
|
|
76
87
|
}
|
|
77
|
-
}, [angle]);
|
|
88
|
+
}, [angle, (_ref$current = ref.current) == null ? void 0 : (_ref$current$parent = _ref$current.parent) == null ? void 0 : _ref$current$parent.geometry]);
|
|
78
89
|
React.useLayoutEffect(() => {
|
|
79
90
|
const group = ref.current;
|
|
91
|
+
console.log(group.children.length);
|
|
80
92
|
const mesh = group.children[0];
|
|
81
93
|
|
|
82
94
|
if (mesh) {
|