diff --git a/gui/gui.js b/gui/gui.js index 9e85b6fa..b31db348 100644 --- a/gui/gui.js +++ b/gui/gui.js @@ -34,6 +34,9 @@ function Gui(sculptgl) this.resetBg_ = this.resetBackground; //reset background this.importBg_ = this.importBackground; //import background image + //functions + this.resetCamera_ = this.resetCamera; //reset camera position and rotation + //misc this.dummyFunc_ = function () {}; //empty function... stupid trick to get a simple button in dat.gui } @@ -100,6 +103,7 @@ Gui.prototype = { //Camera fold var cameraFold = gui.addFolder('Camera'); + cameraFold.add(this, 'resetCamera_').name('Reset'); var optionsCameraMode = { 'Spherical': Camera.mode.SPHERICAL, 'Plane': Camera.mode.PLANE @@ -130,8 +134,7 @@ Gui.prototype = { var ctrlPivot = cameraFold.add(main.camera_, 'usePivot_').name('Picking pivot'); ctrlPivot.onChange(function () { - if (main.mesh_) - main.camera_.reset(main.mesh_); + main.camera_.toggleUsePivot(); main.render(); }); cameraFold.open(); @@ -277,6 +280,13 @@ Gui.prototype = { } }, + /** Immort background */ + resetCamera: function () + { + this.sculptgl_.camera_.reset(); + this.sculptgl_.render(); + }, + /** Immort background */ importBackground: function () { @@ -347,4 +357,4 @@ Gui.prototype = { } Export.exportSketchfab(this.sculptgl_.mesh_, this.keySketchfab_); } -}; +}; \ No newline at end of file diff --git a/math3d/camera.js b/math3d/camera.js index 079974bd..402a1d2e 100644 --- a/math3d/camera.js +++ b/math3d/camera.js @@ -90,18 +90,15 @@ Camera.prototype = { updateView: function () { var view = this.view_; - var tx = this.usePivot_ ? 0 : this.transX_; - var ty = this.usePivot_ ? 0 : this.transY_; + var tx = this.transX_; + var ty = this.transY_; if (this.type_ === Camera.projType.PERSPECTIVE) mat4.lookAt(view, [tx, ty, this.zoom_], [tx, ty, 0], [0, 1, 0]); else mat4.lookAt(view, [tx, ty, 1000], [tx, ty, 0], [0, 1, 0]); mat4.mul(view, view, mat4.fromQuat(mat4.create(), this.rot_)); - if (this.usePivot_) - { - var center = this.center_; - mat4.translate(view, view, [-center[0], -center[1], -center[2]]); - } + var center = this.center_; + mat4.translate(view, view, [-center[0], -center[1], -center[2]]); }, /** Update projection matrix */ @@ -155,16 +152,22 @@ Camera.prototype = { return vec3.transformMat3(pos, pos, mat3.transpose(rot, rot)); }, + /** Reset camera when we toggle usePivot */ + toggleUsePivot: function () + { + this.transX_ = 0; + this.transY_ = 0; + }, + /** Reset camera */ - reset: function (mesh) + reset: function () { - this.rot_ = quat.create(); - this.zoom_ = 0; - this.center_ = [0, 0, 0]; this.transX_ = 0; this.transY_ = 0; - var length = vec3.dist(mesh.octree_.aabbLoose_.max_, mesh.octree_.aabbLoose_.min_); - this.speed_ = length; + this.speed_ = Mesh.globalScale_ * 1.4; + this.rot_ = quat.create(); + this.center_ = [0, 0, 0]; + this.zoom_ = 0; this.zoom(-0.4); }, @@ -210,4 +213,4 @@ Camera.prototype = { var height = this.height_; return [(vec[0] / w + 1) * this.width_ * 0.5, height - (vec[1] / w + 1) * height * 0.5, (vec[2] / w + 1) * 0.5]; } -}; +}; \ No newline at end of file diff --git a/sculptgl.js b/sculptgl.js index 7a19c44f..be0d9d77 100644 --- a/sculptgl.js +++ b/sculptgl.js @@ -621,7 +621,7 @@ SculptGL.prototype = { mesh.initMesh(this.textures_, this.shaders_); mesh.moveTo([0, 0, 0]); - this.camera_.reset(mesh); + this.camera_.reset(); this.gui_.updateMesh(mesh); this.render(); },