Skip to content

Commit

Permalink
Buffer nits
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi committed Sep 27, 2024
1 parent 0de3285 commit 440a3e2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
4 changes: 1 addition & 3 deletions src/viser/client/src/SceneTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,7 @@ function useObjectFactory(message: SceneNodeMessage | undefined): {
),
)
}
colors={new Float32Array(message.props.colors).map(
(val) => val / 255.0,
)}
colors={new Uint8Array(message.props.colors)}
/>
),
};
Expand Down
17 changes: 7 additions & 10 deletions src/viser/client/src/ThreeAssets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,17 @@ export const PointCloud = React.forwardRef<
/** We visualize each point as a 2D ball, which is defined by some norm. */
pointBallNorm: number;
points: Float32Array;
colors: Float32Array;
colors: Uint8Array;
}
>(function PointCloud(props, ref) {
const getThreeState = useThree((state) => state.get);

const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(props.points, 3),
);
geometry.setAttribute("position", new THREE.BufferAttribute(props.points, 3));
geometry.computeBoundingSphere();
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(props.colors, 3),
new THREE.BufferAttribute(props.colors, 3, true),
);

const [material] = React.useState(
Expand Down Expand Up @@ -473,7 +470,7 @@ export const ViserMesh = React.forwardRef<
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
new THREE.BufferAttribute(
new Float32Array(
message.props.vertices.buffer.slice(
message.props.vertices.byteOffset,
Expand All @@ -486,7 +483,7 @@ export const ViserMesh = React.forwardRef<
);

geometry.setIndex(
new THREE.Uint32BufferAttribute(
new THREE.BufferAttribute(
new Uint32Array(
message.props.faces.buffer.slice(
message.props.faces.byteOffset,
Expand Down Expand Up @@ -553,7 +550,7 @@ export const ViserMesh = React.forwardRef<

geometry.setAttribute(
"skinIndex",
new THREE.Uint16BufferAttribute(
new THREE.BufferAttribute(
new Uint16Array(
message.props.skin_indices.buffer.slice(
message.props.skin_indices.byteOffset,
Expand All @@ -566,7 +563,7 @@ export const ViserMesh = React.forwardRef<
);
geometry.setAttribute(
"skinWeight",
new THREE.Float32BufferAttribute(
new THREE.BufferAttribute(
new Float32Array(
message.props.skin_weights!.buffer.slice(
message.props.skin_weights!.byteOffset,
Expand Down

0 comments on commit 440a3e2

Please sign in to comment.