From baa0c4b2fca251bb6267b71ed9c7f1142e7992d6 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 3 Sep 2021 18:31:31 +0200 Subject: add 3d stuff and other stuff --- src/graph.js | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'src/graph.js') diff --git a/src/graph.js b/src/graph.js index 0b2917c..a210f23 100644 --- a/src/graph.js +++ b/src/graph.js @@ -5,7 +5,7 @@ import { union } from "./utils/set_utils.js"; const IMG_SCALE = 20; -export default function buildGraph(db, handlers) { +export default function buildGraph({ db, objects, handlers }) { const linkable = {}; const groups = {}; const data = { nodes: [], links: [] }; @@ -56,7 +56,6 @@ export default function buildGraph(db, handlers) { /** * find common links */ - data.links.forEach((link) => { const a = data.nodes[link.source]; const b = data.nodes[link.target]; @@ -79,14 +78,30 @@ export default function buildGraph(db, handlers) { .showNavInfo(false) .nodeLabel((node) => node.title) .nodeThreeObject((node) => { - let sprite; - if (node.data.thumbnail?.uri) { - const imgTexture = new THREE.TextureLoader().load( - node.data.thumbnail.uri - ); + let sprite, material, texture, video; + if (node.data.object) { + const object = node.data.object; + var box = new THREE.Box3().setFromObject(object); + var center = new THREE.Vector3(); + box.getCenter(center); + object.position.sub(center); + object.scale.set(100, 100, 100); + return object; + } else if (node.data.thumbnail?.uri) { + if (node.data.thumbnail.type === "video") { + video = document.createElement("video"); + video.src = node.data.thumbnail.uri; + video.muted = true; + video.loop = true; + video.autoplay = true; + video.play(); + texture = new THREE.VideoTexture(video); + } else { + texture = new THREE.TextureLoader().load(node.data.thumbnail.uri); + } // console.log(imgTexture); const aspect = node.data.thumbnail.width / node.data.thumbnail.height; - const material = new THREE.SpriteMaterial({ map: imgTexture }); + material = new THREE.SpriteMaterial({ map: texture }); sprite = new THREE.Sprite(material); sprite.scale.set(IMG_SCALE, IMG_SCALE / aspect); return sprite; @@ -113,7 +128,7 @@ export default function buildGraph(db, handlers) { { x: 0, y: 0, z: 0 }, 0 ); - setTimeout(() => zoomOut(1000)); + setTimeout(() => zoomOut(1000), 1000); }; const zoomOut = (duration = 1000) => { -- cgit v1.2.3-70-g09d2