Skip to content

Commit 1bb5b95

Browse files
authored
feat(GradientTexture): support any color representation in GradientTexture (#1993)
1 parent 5560793 commit 1bb5b95

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/core/GradientTexture.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import * as React from 'react'
22
import { useThree } from '@react-three/fiber'
3+
import * as THREE from 'three'
4+
35
export enum GradientType {
46
Linear = 'linear',
57
Radial = 'radial',
68
}
79

810
type Props = {
911
stops: Array<number>
10-
colors: Array<string>
12+
colors: Array<THREE.ColorRepresentation>
1113
attach?: string
1214
size?: number
1315
width?: number
@@ -53,9 +55,10 @@ export function GradientTexture({
5355
)
5456
}
5557

58+
const tempColor = new THREE.Color() // reuse instance for performance
5659
let i = stops.length
5760
while (i--) {
58-
gradient.addColorStop(stops[i], colors[i])
61+
gradient.addColorStop(stops[i], tempColor.set(colors[i]).getStyle())
5962
}
6063
context.save()
6164
context.fillStyle = gradient

0 commit comments

Comments
 (0)