11import * as THREE from "three" ;
22import { useMesh } from "./useMesh" ;
3- import { useCamera } from "../../utils/useCamera" ;
4- import { useCallback , useMemo } from "react" ;
3+ import { useCamera } from "../../../ utils/useCamera" ;
4+ import { useCallback , useMemo , useRef } from "react" ;
55import { RootState } from "@react-three/fiber" ;
6- import { PointerValues , usePointer } from "../../utils/usePointer" ;
7- import { setUniform } from "../../utils/setUniforms" ;
8- import { HooksProps , HooksReturn } from "../types" ;
9- import { useParams } from "../../utils/useParams" ;
10- import { DoubleRenderTarget , useDoubleFBO } from "../../utils/useDoubleFBO" ;
6+ import { PointerValues , usePointer } from "../../../ utils/usePointer" ;
7+ import { setUniform } from "../../../ utils/setUniforms" ;
8+ import { HooksProps , HooksReturn } from "../../ types" ;
9+ import { useParams } from "../../../ utils/useParams" ;
10+ import { DoubleRenderTarget , useDoubleFBO } from "../../../ utils/useDoubleFBO" ;
1111
1212export type BrushParams = {
1313 /** Texture applied to the brush, textureがtrueの場合はcolorよりも優先するよ , default:false */
@@ -32,8 +32,8 @@ export type BrushParams = {
3232 isCursor ?: boolean ;
3333 /** 筆圧 , default : 1.0 */
3434 pressure ?: number ;
35- /** usePointerをframeで呼び出す場合、この値にPointerValuesをセットすることで、2重の呼び出しを防ぎます , default:false */
36- pointerValues ?: PointerValues | false ;
35+ /** When calling usePointer in a frame loop, setting PointerValues to this value prevents double calls , default:null */
36+ pointerValues ?: PointerValues | null ;
3737} ;
3838
3939export type BrushObject = {
@@ -56,7 +56,7 @@ export const BRUSH_PARAMS: BrushParams = {
5656 color : new THREE . Vector3 ( 1.0 , 0.0 , 0.0 ) ,
5757 isCursor : false ,
5858 pressure : 1.0 ,
59- pointerValues : false ,
59+ pointerValues : null ,
6060} ;
6161
6262/**
@@ -81,6 +81,8 @@ export const useBrush = ({
8181
8282 const [ params , setParams ] = useParams < BrushParams > ( BRUSH_PARAMS ) ;
8383
84+ const pressureEnd = useRef < number | null > ( null ) ;
85+
8486 const updateFx = useCallback (
8587 ( props : RootState , updateParams ?: BrushParams ) => {
8688 const { gl, pointer } = props ;
@@ -108,12 +110,7 @@ export const useBrush = ({
108110 setUniform ( material , "uMotionBlur" , params . motionBlur ! ) ;
109111 setUniform ( material , "uMotionSample" , params . motionSample ! ) ;
110112
111- let pointerValues : PointerValues ;
112- if ( params . pointerValues ! ) {
113- pointerValues = params . pointerValues ;
114- } else {
115- pointerValues = updatePointer ( pointer ) ;
116- }
113+ const pointerValues = params . pointerValues ! ?? updatePointer ( pointer ) ;
117114
118115 if ( pointerValues . isVelocityUpdate ) {
119116 setUniform ( material , "uMouse" , pointerValues . currentPointer ) ;
@@ -128,7 +125,14 @@ export const useBrush = ({
128125 setUniform ( material , "uColor" , color ) ;
129126
130127 setUniform ( material , "uIsCursor" , params . isCursor ! ) ;
131- setUniform ( material , "uPressure" , params . pressure ! ) ;
128+
129+ // pressure
130+ setUniform ( material , "uPressureEnd" , params . pressure ! ) ;
131+ if ( pressureEnd . current === null ) {
132+ pressureEnd . current = params . pressure ! ;
133+ }
134+ setUniform ( material , "uPressureStart" , pressureEnd . current ) ;
135+ pressureEnd . current = params . pressure ! ;
132136
133137 return updateRenderTarget ( gl , ( { read } ) => {
134138 setUniform ( material , "uBuffer" , read ) ;
0 commit comments