Created
May 24, 2019 08:22
-
-
Save linonetwo/3507a5fa5c37516d6e98a9302cfb5835 to your computer and use it in GitHub Desktop.
#react hook #api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function useScene( | |
canvasRef: React.RefObject<HTMLCanvasElement>, | |
cameraRef: React.MutableRefObject<Camera | undefined>, | |
currentAirplaneObject, | |
currentDetectedPointObjects: Mesh[], | |
) { | |
// set up scene and model | |
const sceneRef = useRef<Scene>(); | |
useEffect(() => { | |
// 如果这个 Effect 被调用了,说明场景需要刷新 | |
sceneRef.current = new Scene(); | |
if (canvasRef.current && cameraRef.current && currentAirplaneObject && currentDetectedPointObjects.length > 0) { | |
const lights = [ | |
new PointLight(0xffffff, 0.5, 0), | |
new PointLight(0xffffff, 0.8, 0), | |
new PointLight(0xffffff, 1.0, 0), | |
]; | |
lights[0].position.set(20, 20, 20); | |
lights[1].position.set(20, 20, -20); | |
lights[2].position.set(-100, -200, -100); | |
sceneRef.current.add(new AmbientLight(0xffffff, 1), ...lights); | |
const axesHelper = new AxesHelper(5); | |
sceneRef.current.add(axesHelper); | |
sceneRef.current.add(currentAirplaneObject.scene); | |
sceneRef.current.add(...currentDetectedPointObjects); | |
} | |
}, [currentAirplaneObject, currentDetectedPointObjects]); | |
return sceneRef; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const [currentScale, setScale] = useState<{ | |
x: number; | |
y: number; | |
}>({ x: 1, y: 1 }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const [currentPic, setPic] = useState(''); | |
// load pic | |
useEffect(() => { | |
if (!currentPic) { | |
setPic('xxx'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment