Create new views and annotation sets

Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
2024-11-19 08:53:02 -07:00
parent 0dd9aba2b6
commit e92b319a85
3 changed files with 156 additions and 66 deletions

View File

@@ -1,5 +1,3 @@
let currentSet = 'default'
/**
* Convert text in the preview text editor to js object
*
@@ -27,9 +25,9 @@ extractMvconfig = function() {
/**
* Reads the json string in the edit panel
* and updates hotspot elements
* and updates hotspot elements and menu settings
*
* @return {bool} true on successful read and update
* @return {bool|object} arrays of view and set names on successful read and update false on failure
*/
readMvconfig = function() {
let hotspotsObj = []
@@ -63,6 +61,7 @@ readMvconfig = function() {
console.warn('Failed to read model config:' + err.message)
return false
}
const currentSet = $('model-viewer').attr('currentSet') || 'default'
if (currentSet != 'default' && mvconfig.annotationSets[currentSet]) {
mvconfig.annotationSets[currentSet].forEach(hs => {
createHotspot(hs, slotNum)
@@ -84,7 +83,10 @@ readMvconfig = function() {
mView.appendChild(hs)
})
return true
return {
set: Object.keys(mvconfig.annotationSets),
view: Object.keys(mvconfig.viewerConfig)
}
}
/**
@@ -160,6 +162,40 @@ toggleCameraControl = function(view) {
return newControl
}
/**
* Add a new annoation set object to annotatsionSets array
*
* @param {string} newSet name of new view config
*/
addAnnotationSet = function(newSet) {
const mView = $('model-viewer')[0]
let [currentText, mvconfig] = extractMvconfig()
mvconfig.annotationSets[newSet] = []
const textUpdate = currentText.replace(/(?<=<mvconfig>)([\S\s]*?)(?=<\/mvconfig>)/gm,`\n${JSON.stringify(mvconfig, null, 2)}\n`)
$('#wpTextbox1').val(textUpdate)
selectAnnotationSet(newSet)
}
/**
* Add a new set of view configurations to viewerConfig
*
* @param {string} newView name of new view config
*/
addViewConfig = function(newView) {
const mView = $('model-viewer')[0]
let [currentText, mvconfig] = extractMvconfig()
mvconfig.viewerConfig[newView] = { "camera-controls": true }
const textUpdate = currentText.replace(/(?<=<mvconfig>)([\S\s]*?)(?=<\/mvconfig>)/gm,`\n${JSON.stringify(mvconfig, null, 2)}\n`)
$('#wpTextbox1').val(textUpdate)
selectViewConfig(newView)
}
/**
* Switch the current model-viewer attributes to a different
* set of configurations in the mvconfig data
*
* @param {string} view the view name (viewerConfig object key)
*/
selectViewConfig = function(view) {
const mView = $('model-viewer')[0]
let [_, mvconfig] = extractMvconfig()
@@ -242,28 +278,4 @@ writeCameraLimit = function(axis, limit) {
mView.setAttribute(`${limit}-camera-orbit`, oldOrbitVals.join(' '))
const textUpdate = currentText.replace(/(?<=<mvconfig>)([\S\s]*?)(?=<\/mvconfig>)/gm,`\n${JSON.stringify(mvconfig, null, 2)}\n`)
$('#wpTextbox1').val(textUpdate)
}
/**
* Change the currently selected annotation set
*
* @param {string} newSet name of annotation set to select
*/
selectAnnotationSet = function(newSet) {
currentSet = newSet
readMvconfig()
}
/*
export default {
extractMvconfig,
readMvconfig,
writeMvconfig,
orb2degree,
toggleCameraControl,
selectViewConfig,
writeCameraOrbit,
writeCameraLimit,
selectAnnotationSet
}
*/
}