Skip to content

Commit

Permalink
feat(GradientTexture): support any color representation in GradientTe…
Browse files Browse the repository at this point in the history
…xture (#1993)
  • Loading branch information
lukehorvat authored Jun 15, 2024
1 parent 5560793 commit 1bb5b95
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/core/GradientTexture.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import * as React from 'react'
import { useThree } from '@react-three/fiber'
import * as THREE from 'three'

export enum GradientType {
Linear = 'linear',
Radial = 'radial',
}

type Props = {
stops: Array<number>
colors: Array<string>
colors: Array<THREE.ColorRepresentation>
attach?: string
size?: number
width?: number
Expand Down Expand Up @@ -53,9 +55,10 @@ export function GradientTexture({
)
}

const tempColor = new THREE.Color() // reuse instance for performance
let i = stops.length
while (i--) {
gradient.addColorStop(stops[i], colors[i])
gradient.addColorStop(stops[i], tempColor.set(colors[i]).getStyle())
}
context.save()
context.fillStyle = gradient
Expand Down

0 comments on commit 1bb5b95

Please sign in to comment.