Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: polish block sizing #913

Merged
merged 3 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { IFeedBlockData } from "../../models/api/stardust/feed/IFeedBlockData";
import { StardustFeedClient } from "../../services/stardust/stardustFeedClient";
import { Wrapper } from "./wrapper/Wrapper";
import "./Visualizer.scss";
import { IFeedBlockMetadata } from "~/models/api/stardust/feed/IFeedBlockMetadata";

const features = {
statsEnabled: true,
Expand Down Expand Up @@ -48,7 +49,6 @@ const VisualizerInstance: React.FC<RouteComponentProps<VisualizerRouteProps>> =
const isPlaying = useConfigStore(s => s.isPlaying);
const setIsPlaying = useConfigStore(s => s.setIsPlaying);
const addBlock = useTangleStore(s => s.addToBlockQueue);
const addToScaleQueue = useTangleStore(s => s.addToScaleQueue);
const addToEdgeQueue = useTangleStore(s => s.addToEdgeQueue);
const addToColorQueue = useTangleStore(s => s.addToColorQueue);
const addYPosition = useTangleStore(s => s.addYPosition);
Expand Down Expand Up @@ -122,7 +122,6 @@ const VisualizerInstance: React.FC<RouteComponentProps<VisualizerRouteProps>> =
};
}, []);


/**
* Subscribe to updates
* @param blockData The new block data
Expand Down Expand Up @@ -155,7 +154,6 @@ const VisualizerInstance: React.FC<RouteComponentProps<VisualizerRouteProps>> =
blockIdToPosition.set(blockData.blockId, position);
blockMetadata.set(blockData.blockId, blockData);

addToScaleQueue(blockData.blockId, blockData.parents ?? []);
addToEdgeQueue(blockData.blockId, blockData.parents ?? []);
addYPosition(Y);
}
Expand Down
23 changes: 0 additions & 23 deletions client/src/features/visualizer-threejs/store/tangle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ interface TangleState {
addToBlockQueue: (newBlock: BlockState) => void;
removeFromBlockQueue: (blockIds: string[]) => void;

scaleQueue: string[];
addToScaleQueue: (blockId: string, parents: string[]) => void;
removeFromScaleQueue: (blockIds: string[]) => void;

edgeQueue: Edge[];
addToEdgeQueue: (blockId: string, parents: string[]) => void;
removeFromEdgeQueue: (edges: Edge[]) => void;
Expand Down Expand Up @@ -63,7 +59,6 @@ interface TangleState {

export const useTangleStore = create<TangleState>()(devtools(set => ({
blockQueue: [],
scaleQueue: [],
edgeQueue: [],
colorQueue: [],
blockIdToEdges: new Map(),
Expand All @@ -86,24 +81,6 @@ export const useTangleStore = create<TangleState>()(devtools(set => ({
blockQueue: state.blockQueue.filter(b => !blockIds.includes(b.id))
}));
},
addToScaleQueue: (_: string, parents: string[]) => {
if (parents.length > 0) {
set(state => {
const nextScalesToUpdate = [...state.scaleQueue, ...parents];

return {
...state,
scaleQueue: nextScalesToUpdate
};
});
}
},
removeFromScaleQueue: (blockIds: string[]) => {
set(state => ({
...state,
scaleQueue: state.scaleQueue.filter(blockId => !blockIds.includes(blockId))
}));
},
addToEdgeQueue: (blockId: string, parents: string[]) => {
if (parents.length > 0) {
set(state => {
Expand Down
34 changes: 3 additions & 31 deletions client/src/features/visualizer-threejs/useRenderTangle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useRenderEdges } from "./useRenderEdges";
const SPHERE_GEOMETRY = new THREE.SphereGeometry(NODE_SIZE_DEFAULT, 32, 16);
const SPHERE_MATERIAL = new THREE.MeshPhongMaterial();
const SPHERE_TEMP_OBJECT = new THREE.Object3D();
const SCALE_INCREMENT = 0.1;
const INITIAL_SPHERE_SCALE = 0.7;

export const useRenderTangle = () => {
const tangleMeshRef = useRef(new THREE.InstancedMesh(SPHERE_GEOMETRY, SPHERE_MATERIAL, MAX_BLOCK_INSTANCES));
Expand All @@ -19,8 +19,6 @@ export const useRenderTangle = () => {

const blockQueue = useTangleStore(s => s.blockQueue);
const removeFromBlockQueue = useTangleStore(s => s.removeFromBlockQueue);
const scaleQueue = useTangleStore(s => s.scaleQueue);
const removeFromScaleQueue = useTangleStore(s => s.removeFromScaleQueue);

const colorQueue = useTangleStore(s => s.colorQueue);
const removeFromColorQueue = useTangleStore(s => s.removeFromColorQueue);
Expand Down Expand Up @@ -66,7 +64,7 @@ export const useRenderTangle = () => {
tangleMeshRef.current.instanceMatrix.setUsage(THREE.DynamicDrawUsage);

// Set the scale of all instances to 0 to make then initially invisible
// We will set the scale back to one, as actual blocks are added
// We will set the scale back to initial when actual blocks are added
for (let i = 0; i < MAX_BLOCK_INSTANCES; i++) {
SPHERE_TEMP_OBJECT.scale.setScalar(0);
SPHERE_TEMP_OBJECT.updateMatrix();
Expand All @@ -77,32 +75,6 @@ export const useRenderTangle = () => {
}
}, [tangleMeshRef]);

useEffect(() => {
if (scaleQueue.length > 0) {
for (const blockIdToScale of scaleQueue) {
const indexToUpdate = blockIdToIndex.get(blockIdToScale);

if (indexToUpdate) {
const blockMatrix = new THREE.Matrix4();
tangleMeshRef.current.getMatrixAt(indexToUpdate, blockMatrix);

const blockObj = new THREE.Object3D();
blockObj.applyMatrix4(blockMatrix);

blockObj.scale.setScalar(blockObj.scale.x + SCALE_INCREMENT);

blockObj.updateMatrix();

tangleMeshRef.current.setMatrixAt(indexToUpdate, blockObj.matrix);
}
}

tangleMeshRef.current.instanceMatrix.needsUpdate = true;

removeFromScaleQueue(scaleQueue);
}
}, [scaleQueue]);

useEffect(() => {
if (blockQueue.length === 0) {
return;
Expand All @@ -115,7 +87,7 @@ export const useRenderTangle = () => {
const color = block.color;

SPHERE_TEMP_OBJECT.position.set(x, y, z);
SPHERE_TEMP_OBJECT.scale.setScalar(1);
SPHERE_TEMP_OBJECT.scale.setScalar(INITIAL_SPHERE_SCALE);
begonaalvarezd marked this conversation as resolved.
Show resolved Hide resolved
SPHERE_TEMP_OBJECT.updateMatrix();

updateBlockIdToIndex(block.id, objectIndexRef.current);
Expand Down