Skip to content

Instantly share code, notes, and snippets.

@linonetwo
Created May 24, 2019 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linonetwo/3507a5fa5c37516d6e98a9302cfb5835 to your computer and use it in GitHub Desktop.
Save linonetwo/3507a5fa5c37516d6e98a9302cfb5835 to your computer and use it in GitHub Desktop.
#react hook #api
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;
}
const [currentScale, setScale] = useState<{
x: number;
y: number;
}>({ x: 1, y: 1 });
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