Listen for ATON Tap event
This commit is contained in:
@@ -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',
|
||||
|
||||
25
js/scene.js
25
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
|
||||
|
||||
@@ -24,6 +24,7 @@ let AppState = {
|
||||
*/
|
||||
normalizedNodes: [],
|
||||
treeNodes: {},
|
||||
semanticNodes: new Map,
|
||||
mainNodeId: null,
|
||||
currentScene: null,
|
||||
sceneHasAudio: false,
|
||||
|
||||
@@ -29,3 +29,18 @@ 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);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user