WIP semantic sphere
This commit is contained in:
49
js/scene.js
49
js/scene.js
@@ -46,6 +46,16 @@ function init () {
|
||||
AppState.exposure = config.scene.initialExposure;
|
||||
|
||||
ATON.Nav.setUserControl(true);
|
||||
// General hover/leave events handling for all existing semantic nodes.
|
||||
ATON.on("SemanticNodeHover", (semid) =>{ // When hovering a semantic node...
|
||||
let semNode = ATON.getSemanticNode(semid);
|
||||
if (semNode) semNode.highlight();
|
||||
});
|
||||
|
||||
ATON.on("SemanticNodeLeave", (semid) =>{
|
||||
let semNode = ATON.getSemanticNode(semid);
|
||||
if (semNode) semNode.restoreDefaultMaterial();
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @param {Object} marker - The marker object from config
|
||||
@@ -67,8 +77,16 @@ export function openScene (marker, nodes) {
|
||||
toggleAmbientOcclusion(config.scene.ambientOcclusion);
|
||||
AppState.ambientOcclusion = config.scene.ambientOcclusion;
|
||||
AppState.root = ATON.getRootScene();
|
||||
}
|
||||
|
||||
// Add semantic nodes
|
||||
for (let node of AppState.nodes) {
|
||||
if (node.isSemantic) {
|
||||
createSemanticNode(ATON.getSceneNode(node.id).getBound(), node.id);
|
||||
// DEBUG!!
|
||||
console.debug(ATON.getSceneNode(node.id).getBound());
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param {Object[]} nodes
|
||||
@@ -104,10 +122,37 @@ function loadNodes(nodes) {
|
||||
AppState.clipping.boundingSphere = node.getBound();
|
||||
}
|
||||
|
||||
AppState.nodes.push({id: n.label, active: n.isInvisible ? false: true});
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user