Skip to content

Commit

Permalink
fix: allow clipping planes to be used with Outlines (#2133)
Browse files Browse the repository at this point in the history
  • Loading branch information
Archimagus authored Jan 12, 2025
1 parent 715a9f5 commit 3463269
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/abstractions/outlines.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type OutlinesProps = JSX.IntrinsicElements['group'] & {
thickness: number
/** Geometry crease angle (0 === no crease), default: Math.PI */
angle: number
/** Clipping planes, default: null (no clipping) works the same as clipping planes on any material */
clippingPlanes: THREE.Plane[] | null
}
```
Expand Down
8 changes: 8 additions & 0 deletions src/core/Outlines.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const OutlinesMaterial = /* @__PURE__ */ shaderMaterial(
`#include <common>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <clipping_planes_pars_vertex>
uniform float thickness;
uniform bool screenspace;
uniform vec2 size;
Expand All @@ -31,6 +32,7 @@ const OutlinesMaterial = /* @__PURE__ */ shaderMaterial(
#include <morphtarget_vertex>
#include <skinning_vertex>
#include <project_vertex>
#include <clipping_planes_vertex>
vec4 tNormal = vec4(normal, 0.0);
vec4 tPosition = vec4(transformed, 1.0);
#ifdef USE_INSTANCING
Expand All @@ -50,7 +52,9 @@ const OutlinesMaterial = /* @__PURE__ */ shaderMaterial(
}`,
`uniform vec3 color;
uniform float opacity;
#include <clipping_planes_pars_fragment>
void main(){
#include <clipping_planes_fragment>
gl_FragColor = vec4(color, opacity);
#include <tonemapping_fragment>
#include <${version >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
Expand All @@ -70,6 +74,7 @@ type OutlinesProps = JSX.IntrinsicElements['group'] & {
thickness?: number
/** Geometry crease angle (0 === no crease), default: Math.PI */
angle?: number
clippingPlanes?: THREE.Plane[]
toneMapped?: boolean
polygonOffset?: boolean
polygonOffsetFactor?: number
Expand All @@ -87,6 +92,7 @@ export function Outlines({
renderOrder = 0,
thickness = 0.05,
angle = Math.PI,
clippingPlanes,
...props
}: OutlinesProps) {
const ref = React.useRef<THREE.Group>()
Expand Down Expand Up @@ -150,6 +156,8 @@ export function Outlines({
toneMapped,
polygonOffset,
polygonOffsetFactor,
clippingPlanes,
clipping: clippingPlanes && clippingPlanes.length > 0,
})
}
})
Expand Down

0 comments on commit 3463269

Please sign in to comment.