Test semantic node

This commit is contained in:
2026-05-20 11:45:51 +02:00
parent aa9a6f56b6
commit f5f105e786
3 changed files with 70 additions and 3 deletions

View File

@@ -16,7 +16,7 @@ const theater2Popup = `
export const config = {
scene : {
initialExposure: 0.85,
initialExposure: 0.95,
autoLP: false,
shadows: false,
initLightDir: [0.2,-0.3,-0.7],
@@ -111,6 +111,7 @@ export const config = {
{
label: 'Palcoscenico',
model: 'models/ssgp/Teatro_SSGP_Palcoscenico.glb',
isSemantic: true,
},
{
label: 'Boccascena / Proscenio',

View File

@@ -37,7 +37,6 @@ function init () {
ATON.setMainLightDirection(new THREE.Vector3(...config.scene.initLightDir));
ATON.toggleShadows(config.scene.shadows);
ATON.setExposure(config.scene.initialExposure);
// Open settings side panel when clicking on settings btn
AppState.camera = ATON.Nav._camera;
AppState.renderer = ATON._renderer;
@@ -106,10 +105,63 @@ function loadNodes(nodes) {
AppState.clipping.boundingSphere = node.getBound();
}
AppState.nodes.push({id: n.label, active: n.isInvisible ? false: true});
if (n.isSemantic) {
createSemanticNode(n.model, n.label);
//ATON.getSemanticRoot().attach(semNode);
}
AppState.nodes.push({
id: n.label,
active: n.isInvisible ? false: true,
isSemantic: n.isSemantic
});
});
if (!AppState.clipping.boundingSphere) {
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
* @param {string} id The original scene node ID (3D object)
* @returns {ATON.SceneNode}
*/
function createSemanticNode(model, id) {
// Default/highlight materials for semantic node
let matSemDef = ATON.MatHub.materials.semanticShape;
let matSemHL = ATON.MatHub.materials.semanticShapeHL;
const semNode = ATON.createSemanticNode(id)
.load(model)
.setDefaultAndHighlightMaterials(matSemDef, matSemHL)
.attachToRoot();
semNode.setRotation(...config.scene.initRotation);
return semNode;
}

View File

@@ -15,3 +15,17 @@ AppState.treeNodes = tree;
// TODO: add Map object for lookup optimization
openScene(marker, AppState.normalizedNodes);
// General hover/leave events handling for all semantic nodes.
ATON.on("SemanticNodeHover", (semid) => {
let node = ATON.getSemanticNode(semid);
console.debug('Sem node:', semid);
if (node) node.highlight();
});
ATON.on("SemanticNodeLeave", (semid) => {
let node = ATON.getSemanticNode(semid);
if (node) node.restoreDefaultMaterial();
});