Skip to content
Draft
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
18 changes: 12 additions & 6 deletions src/components/ThreeScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const [labelPositions, setLabelPositions] = useState<
const defaultLineOpacity = 0.1;
let outlineMesh: THREE.Mesh | null = null;
let previouslyHoveredSphere: THREE.Mesh | null = null;
let highlightedLines: THREE.Line[] = [];

type OverlayInfo = { overlay: HTMLDivElement, node: THREE.Object3D };
let neighborOverlays: OverlayInfo[] = [];
Expand Down Expand Up @@ -166,6 +167,7 @@ const [labelPositions, setLabelPositions] = useState<
const sphereGroup = new THREE.Group();
const lineGroup = new THREE.Group();
const nodeMap: { [key: string]: THREE.Vector3 } = {};
const sphereByLabel = new Map<string, THREE.Object3D>();

data.nodes.forEach((node) => {
//const material = new THREE.MeshNormalMaterial();
Expand All @@ -192,6 +194,7 @@ const [labelPositions, setLabelPositions] = useState<
sphere.userData.displayUrl = `https://scrapbox.io/${projectName}/${node.text}`;
sphere.userData.label = node.text;
sphereGroup.add(sphere);
sphereByLabel.set(node.text, sphere);
/*
sphereGroup.add(sphere);

Expand All @@ -218,10 +221,10 @@ const [labelPositions, setLabelPositions] = useState<
opacity: defaultLineOpacity
});
const line = new THREE.Line(lineGeometry, lineMaterial);
lineGroup.add(line)
lineGroup.add(line);

const sourceSphere = sphereGroup.children.find(o => o.userData.displayUrl?.endsWith(link.source));
const targetSphere = sphereGroup.children.find(o => o.userData.displayUrl?.endsWith(link.target));
const sourceSphere = sphereByLabel.get(link.source);
const targetSphere = sphereByLabel.get(link.target);
if (sourceSphere && targetSphere) {
const sourceWorldPos = new THREE.Vector3();
sourceSphere.getWorldPosition(sourceWorldPos);
Expand Down Expand Up @@ -331,11 +334,13 @@ const [labelPositions, setLabelPositions] = useState<
);
const urlDisplay = urlDisplayRef.current;

lineGroup.children.forEach(line => {
if ((line as THREE.Line).material instanceof THREE.LineBasicMaterial) {
((line as THREE.Line).material as THREE.LineBasicMaterial).opacity = defaultLineOpacity;
// Reset only previously highlighted lines instead of all lines
highlightedLines.forEach(line => {
if (line.material instanceof THREE.LineBasicMaterial) {
(line.material as THREE.LineBasicMaterial).opacity = defaultLineOpacity;
}
});
highlightedLines = [];

if (outlineMesh) {
scene.remove(outlineMesh);
Expand Down Expand Up @@ -426,6 +431,7 @@ const [labelPositions, setLabelPositions] = useState<
lines.forEach((line) => {
const mat = line.material as THREE.LineBasicMaterial;
mat.opacity = 1.0;
highlightedLines.push(line);
});
}
}
Expand Down