diff --git a/config.js b/config.js index f5d4ca5..645ca20 100644 --- a/config.js +++ b/config.js @@ -112,6 +112,13 @@ export const config = { label: 'Palcoscenico', model: 'models/ssgp/Teatro_SSGP_Palcoscenico.glb', isSemantic: true, + // TEMP + content: { + type: 'img', + description: ` + Tommaso Bezzi: Disegno della pianta del teatro di S. Giovanni e Paolo di Venezia, 1691-1693, Sir John Soane's Museum, Londra. + ` + } }, { label: 'Boccascena / Proscenio', diff --git a/js/scene.js b/js/scene.js index f4a273b..94416e3 100644 --- a/js/scene.js +++ b/js/scene.js @@ -109,6 +109,7 @@ function loadNodes(nodes) { if (n.isSemantic) { createSemanticNode(n.model, n.label); + AppState.semanticNodes.set(n.label, n.content); //ATON.getSemanticRoot().attach(semNode); } @@ -123,30 +124,6 @@ function loadNodes(nodes) { console.error("No bounding sphere computed, clipping will fail. Ensure one node has 'isMain: true'."); } } -/** - * Uses a generic sphere shape as semantic annotation - * @param {Sphere} bound The scene node's bounding sphere - * @param {string} id The original scene node ID (3D object) - * @returns {ATON.SceneNode} -function createSemanticNode(bound, id) { - // Default/highlight materials for semantic node - let matSemDef = ATON.MatHub.materials.semanticShape; - let matSemHL = ATON.MatHub.materials.semanticShapeHL; - - const semNode = ATON.createSemanticNode(id) - .setDefaultAndHighlightMaterials(matSemDef, matSemHL) - .attachToRoot(); - - const sphereCenter = bound.center; - const sphereRadius = bound.radius * 0.2; - - let sphere = ATON.SemFactory.createSphere(id, sphereCenter, sphereRadius); - - console.debug('Bound:', bound); - console.debug('Semantic sphere:', sphere); -} -*/ - /** * Creates a semantic annotation from a model * @param {string} model The model's path to load diff --git a/js/state.js b/js/state.js index 230d4f0..973615c 100644 --- a/js/state.js +++ b/js/state.js @@ -24,6 +24,7 @@ let AppState = { */ normalizedNodes: [], treeNodes: {}, + semanticNodes: new Map, mainNodeId: null, currentScene: null, sceneHasAudio: false, diff --git a/scenes/ssgp/index.js b/scenes/ssgp/index.js index ac959f8..6af451b 100644 --- a/scenes/ssgp/index.js +++ b/scenes/ssgp/index.js @@ -28,4 +28,19 @@ ATON.on("SemanticNodeHover", (semid) => { ATON.on("SemanticNodeLeave", (semid) => { let node = ATON.getSemanticNode(semid); if (node) node.restoreDefaultMaterial(); +}); + +// Triggers on mouse click / tap events +ATON.on("Tap", (e) => { + let node = ATON.getHoveredSemanticNode(); + if (node) { + // Retrieve semantic node from AppState to trigger a modal with its content + const content = AppState.semanticNodes.get(node.nid); + + // Triggers a modal to show the content (listened by Stimulus) + const event = new Event('semantic-modal-show'); + event.content = content; + + document.dispatchEvent(event); + } }); \ No newline at end of file