Skip to content

Commit

Permalink
Faster point clouds + outlines
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi committed Feb 8, 2024
1 parent f5bf1fb commit fa3ff41
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/viser/client/src/Outlines.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const Outlines = React.forwardRef<THREE.Group, OutlinesProps>(
const [material] = React.useState(
() => new OutlinesMaterial({ side: THREE.BackSide }),
);
const { gl } = useThree();
const gl = useThree((state) => state.gl);
const contextSize = gl.getDrawingBufferSize(new THREE.Vector2());
React.useMemo(() => extend({ OutlinesMaterial }), []);

Expand Down
8 changes: 5 additions & 3 deletions src/viser/client/src/ThreeAssets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const PointCloud = React.forwardRef<
colors: Float32Array;
}
>(function PointCloud(props, ref) {
const { gl, camera } = useThree();
const getThreeState = useThree((state) => state.get);

const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
Expand Down Expand Up @@ -125,9 +125,11 @@ export const PointCloud = React.forwardRef<
material.uniforms.scale.value =
(props.pointSize /
Math.tan(
(((camera as THREE.PerspectiveCamera).fov / 180.0) * Math.PI) / 2.0,
(((getThreeState().camera as THREE.PerspectiveCamera).fov / 180.0) *
Math.PI) /
2.0,
)) *
gl.getSize(rendererSize).height;
getThreeState().gl.getSize(rendererSize).height;
});
return <points ref={ref} geometry={geometry} material={material} />;
});
Expand Down

0 comments on commit fa3ff41

Please sign in to comment.