Add hotspot functionality
Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
@@ -3,10 +3,11 @@ modelLoad.setAttribute('type','module')
|
||||
modelLoad.setAttribute('src','https://ajax.googleapis.com/ajax/libs/model-viewer/3.5.0/model-viewer.min.js')
|
||||
let headElem = document.getElementsByTagName('head')[0]
|
||||
headElem.appendChild(modelLoad)
|
||||
|
||||
/*
|
||||
let urlProm, dataProm
|
||||
let isFilePageImage = false
|
||||
|
||||
/*
|
||||
let glbElems = document.querySelectorAll('.mw-body-content [href$=".glb"][title$=".glb"')
|
||||
if (glbElems.length > 0) {
|
||||
[...glbElems].forEach((ge, idx) => {
|
||||
@@ -67,4 +68,45 @@ async function getModelMeta(getTitle) {
|
||||
});
|
||||
return JSON.parse($(metaApiResp.parse.text['*']).find('pre').text() || '{}')
|
||||
}
|
||||
*/
|
||||
*/
|
||||
|
||||
if (mw.config.values.wgAction == 'submit') {
|
||||
[...document.getElementsByTagName('model-viewer')].forEach( mv => {
|
||||
mv.disableTap = true;
|
||||
});
|
||||
console.log('Starting point locator...');
|
||||
document.addEventListener('click', e => {
|
||||
var hsPosition = null;
|
||||
var targetModel = e.target.closest('model-viewer');
|
||||
if (targetModel) {
|
||||
hsPosition = targetModel.positionAndNormalFromPoint(e.clientX, e.clientY);
|
||||
}
|
||||
if (hsPosition) {
|
||||
var hsOutput = ['|hotspot=NewHotspot'];
|
||||
hsOutput.push('pos=' + hsPosition.position.toString().replaceAll(/(\d{5})(\d*?m)/g,"$1m"));
|
||||
hsOutput.push('norm=' + hsPosition.normal.toString().replaceAll(/(\d{5})(\d*?m)/g,"$1m"));
|
||||
hsOutput.push('orb=' + targetModel.getCameraOrbit());
|
||||
hsOutput.push('targ=' + targetModel.getCameraTarget());
|
||||
navigator.clipboard.writeText(hsOutput.join('|'));
|
||||
}
|
||||
});
|
||||
}
|
||||
onAnnotation = function(e) {
|
||||
e.stopPropagation();
|
||||
var targetAnnotation = e.target.slot.split('-')[1];
|
||||
var targetModel = e.target.closest('model-viewer');
|
||||
[...targetModel.querySelectorAll('.HotspotAnnotation')].forEach( (an, idx) => {
|
||||
if (idx + 1 == targetAnnotation && an.classList.contains('HiddenAnnotation')) {
|
||||
an.classList.remove('HiddenAnnotation');
|
||||
if (an.parentElement.dataset.target) {targetModel.cameraTarget = an.parentElement.dataset.target}
|
||||
if (an.parentElement.dataset.orbit) {targetModel.cameraOrbit = an.parentElement.dataset.orbit}
|
||||
} else {
|
||||
an.classList.add('HiddenAnnotation');
|
||||
}
|
||||
});
|
||||
};
|
||||
clearAnnotations = function() {
|
||||
[...document.getElementsByClassName('HotspotAnnotation')].forEach( an => {
|
||||
an.classList.add('HiddenAnnotation');
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user