Improve camera orbit and target settings
Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
@@ -75,14 +75,14 @@ const setMinYaw = new OO.ui.ButtonWidget({
|
||||
label: 'Min'
|
||||
})
|
||||
setMinYaw.on('click', () => {
|
||||
limitCameraOrbit('yaw','min')
|
||||
writeCameraLimit('yaw','min')
|
||||
})
|
||||
|
||||
const setMaxYaw = new OO.ui.ButtonWidget({
|
||||
label: 'Max'
|
||||
})
|
||||
setMaxYaw.on('click', () => {
|
||||
limitCameraOrbit('yaw','max')
|
||||
writeCameraLimit('yaw','max')
|
||||
})
|
||||
|
||||
const yawLimitButtons = new OO.ui.ButtonGroupWidget({
|
||||
@@ -105,14 +105,14 @@ const setMinPitch = new OO.ui.ButtonWidget({
|
||||
label: 'Min'
|
||||
})
|
||||
setMinPitch.on('click', () => {
|
||||
limitCameraOrbit('pitch','min')
|
||||
writeCameraLimit('pitch','min')
|
||||
})
|
||||
|
||||
const setMaxPitch = new OO.ui.ButtonWidget({
|
||||
label: 'Max'
|
||||
})
|
||||
setMaxPitch.on('click', () => {
|
||||
limitCameraOrbit('pitch','max')
|
||||
writeCameraLimit('pitch','max')
|
||||
})
|
||||
|
||||
const pitchLimitButtons = new OO.ui.ButtonGroupWidget({
|
||||
|
||||
@@ -108,9 +108,19 @@ extractMetadata = function() {
|
||||
const editText = $('#wpTextbox1').val()
|
||||
const extractMetadata = editText.match(/<mvconfig>([\S\s]*?)<\/mvconfig>/)
|
||||
let metadata = (extractMetadata.length >= 2) ? JSON.parse(extractMetadata[1]) : {viewerConfig: {}, annotations: {}, annotationSets: {}}
|
||||
if (metadata.viewerConfig === undefined) {
|
||||
metadata.viewerConfig = {
|
||||
default: {
|
||||
"camera-controls": true
|
||||
}
|
||||
}
|
||||
}
|
||||
if (metadata.annotations === undefined) {
|
||||
metadata.annotations = {}
|
||||
}
|
||||
if (metadata.annotationSets === undefined) {
|
||||
metadata.annotationSets = {}
|
||||
}
|
||||
return [editText, metadata]
|
||||
}
|
||||
|
||||
@@ -454,12 +464,20 @@ toggleFullScreen = function(glCont) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Send new default camera orbit values to the preview editor
|
||||
* Set new default camera orbit and send values to the preview
|
||||
* editor
|
||||
*/
|
||||
writeCameraOrbit = function() {
|
||||
const mView = $('model-viewer')[0]
|
||||
let newOrbit = orb2degree(mView.getCameraOrbit().toString(),[2,2,5])
|
||||
const textUpdate = $('#wpTextbox1').val().replace(/([\S\s]*?default[\S\s]*?"camera-orbit": ")(.*?)(",$[\S\s]*)/gm,'$1' + newOrbit + '$3')
|
||||
const newOrbit = orb2degree(mView.getCameraOrbit().toString(),[2,2,5])
|
||||
mView.setAttribute('camera-orbit', newOrbit)
|
||||
const targetObj = mView.getCameraTarget()
|
||||
const newTarget = `${targetObj.x.toFixed(5)}m ${targetObj.y.toFixed(5)}m ${targetObj.z.toFixed(5)}m`
|
||||
mView.setAttribute('camera-target', newTarget)
|
||||
let [currentText, mvconfig] = extractMetadata()
|
||||
mvconfig.viewerConfig.default['camera-orbit'] = newOrbit
|
||||
mvconfig.viewerConfig.default['camera-target'] = newTarget
|
||||
const textUpdate = currentText.replace(/(?<=<mvconfig>)([\S\s]*?)(?=<\/mvconfig>)/gm,`\n${JSON.stringify(mvconfig, null, 2)}\n`)
|
||||
$('#wpTextbox1').val(textUpdate)
|
||||
}
|
||||
|
||||
@@ -470,19 +488,19 @@ writeCameraOrbit = function() {
|
||||
* @param {string} axis [yaw|pitch] orbit value to set
|
||||
* @param {string} limit [max|min] limit value to set
|
||||
*/
|
||||
limitCameraOrbit = function(axis, limit) {
|
||||
writeCameraLimit = function(axis, limit) {
|
||||
const mView = $('model-viewer')[0]
|
||||
const newOrbit = orb2degree(mView.getCameraOrbit().toString(),[2,2,5])
|
||||
const newOrbitVals = newOrbit.split(' ')
|
||||
const valueIndex = (axis == 'yaw') ? 0 : 1
|
||||
let [currentText, metadata] = extractMetadata()
|
||||
const oldOrbit = metadata.viewerConfig.default[`${limit}-camera-orbit`]
|
||||
let [currentText, mvconfig] = extractMetadata()
|
||||
const oldOrbit = mvconfig.viewerConfig.default[`${limit}-camera-orbit`]
|
||||
let oldOrbitVals = (oldOrbit) ? oldOrbit.split(' ') : Array(3).fill('auto')
|
||||
oldOrbitVals[valueIndex] = newOrbitVals[valueIndex]
|
||||
metadata.viewerConfig.default[`${limit}-camera-orbit`] = oldOrbitVals.join(' ')
|
||||
mvconfig.viewerConfig.default[`${limit}-camera-orbit`] = oldOrbitVals.join(' ')
|
||||
mView.setAttribute(`${limit}-camera-orbit`, oldOrbitVals.join(' '))
|
||||
const newText = currentText.replace(/(.*?<mvconfig>)[\S\s]*?(<\/mvconfig>.*)/,`$1\n${JSON.stringify(metadata, null, 2)}\n$2`)
|
||||
$('#wpTextbox1').val(newText)
|
||||
const textUpdate = currentText.replace(/(?<=<mvconfig>)([\S\s]*?)(?=<\/mvconfig>)/gm,`\n${JSON.stringify(mvconfig, null, 2)}\n`)
|
||||
$('#wpTextbox1').val(textUpdate)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user