diff --git a/src/kiri/init.js b/src/kiri/init.js index 861cf6c2..3bd72f24 100644 --- a/src/kiri/init.js +++ b/src/kiri/init.js @@ -414,6 +414,9 @@ API.show.local(); break; case cca('v'): // toggle single slice view mode + if (API.view.get() === VIEWS.ARRANGE) { + API.space.set_focus(); + } if (API.var.layer_hi == API.var.layer_lo) { API.var.layer_lo = 0; } else { diff --git a/src/kiri/main.js b/src/kiri/main.js index da537b6d..a10a32c1 100644 --- a/src/kiri/main.js +++ b/src/kiri/main.js @@ -327,7 +327,8 @@ reload: reload, restore: restoreWorkspace, clear: clearWorkspace, - save: saveWorkspace + save: saveWorkspace, + set_focus: setFocus }, tweak, util: { @@ -368,6 +369,25 @@ work: KIRI.work }; + function setFocus(widgets) { + if (widgets === undefined) { + widgets = WIDGETS; + } else if (!Array.isArray) { + widgets = [ widgets ]; + } + let pos = { x:0, y:0, z:0 }; + for (let widget of widgets) { + pos.x += widget.track.pos.x; + pos.y += widget.track.pos.y; + pos.z += widget.track.pos.z; + } + pos.x /= widgets.length; + pos.y /= widgets.length; + pos.z /= widgets.length; + SPACE.platform.setCenter(pos.x, -pos.y, pos.z); + SPACE.view.setFocus(new THREE.Vector3(pos.x, pos.z, -pos.y)); + } + function reload() { API.event.emit('reload'); do_reload(100); diff --git a/src/moto/ctrl.js b/src/moto/ctrl.js index 0155dad6..34d6f439 100644 --- a/src/moto/ctrl.js +++ b/src/moto/ctrl.js @@ -181,6 +181,15 @@ MOTO.CTRL = function (object, domElement, notify, slider) { } }; + this.getTarget = function() { + return this.target; + }; + + this.setTarget = function(t) { + this.target = t; + this.target0 = this.target.clone(); + } + function isValue(v) { return v !== null && v !== undefined; } diff --git a/src/moto/space.js b/src/moto/space.js index b1b1111c..7906b4a2 100644 --- a/src/moto/space.js +++ b/src/moto/space.js @@ -16,7 +16,9 @@ PI2 = PI / 2, PI4 = PI / 4, ROUND = Math.round, + panX = 0, panY = 0, + panZ = 0, gridZOff = 0, platformZOff = 0, perspective = 35, @@ -896,6 +898,7 @@ add: function(o) { WORLD.add(o) }, remove: function(o) { WORLD.remove(o) }, setMaxZ: function(z) { panY = z / 2 }, + setCenter: function(x,y,z) { panX = x; panY = z, panZ = y }, isHidden: function() { return !showPlatform }, setHidden: function(b) { showPlatform = !b; platform.visible = !b }, setHiding: function(b) { hidePlatformBelow = b }, @@ -935,12 +938,12 @@ }, view: { - top: function() { tweenCam({left: 0, up: 0, panX: 0, panY: panY, panZ: 0}) }, - back: function() { tweenCam({left: PI, up: PI2, panX: 0, panY: panY, panZ: 0}) }, - home: function() { tweenCam({left: 0, up: PI4, panX: 0, panY: panY, panZ: 0}) }, - front: function() { tweenCam({left: 0, up: PI2, panX: 0, panY: panY, panZ: 0}) }, - right: function() { tweenCam({left: PI2, up: PI2, panX: 0, panY: panY, panZ: 0}) }, - left: function() { tweenCam({left: -PI2, up: PI2, panX: 0, panY: panY, panZ: 0}) }, + top: function() { tweenCam({left: 0, up: 0, panX, panY, panZ}) }, + back: function() { tweenCam({left: PI, up: PI2, panX, panY, panZ}) }, + home: function() { tweenCam({left: 0, up: PI4, panX, panY, panZ}) }, + front: function() { tweenCam({left: 0, up: PI2, panX, panY, panZ}) }, + right: function() { tweenCam({left: PI2, up: PI2, panX, panY, panZ}) }, + left: function() { tweenCam({left: -PI2, up: PI2, panX, panY, panZ}) }, reset: function() { viewControl.reset(); requestRefresh() }, load: function(cam) { viewControl.setPosition(cam) }, save: function() { return viewControl.getPosition(true) }, @@ -953,7 +956,12 @@ viewControl.setMouse(viewControl.mouseDefault); } }, - getFPS: function() { return fps } + getFPS: function() { return fps }, + getFocus: function() { return viewControl.getTarget() }, + setFocus: function(v) { + viewControl.setTarget(v); + refresh(); + }, }, mouse: {