diff --git a/js/component/card/three_d.js b/js/component/card/three_d.js index 8f5670e..d8fe790 100644 --- a/js/component/card/three_d.js +++ b/js/component/card/three_d.js @@ -27,6 +27,7 @@ beestat.component.card.three_d = function() { }); beestat.dispatcher.addEventListener('cache.data.three_d__runtime_sensor', function() { + self.state_.scene_camera_state = self.scene_.get_camera_state(); self.get_data_(true); self.rerender(); }); @@ -322,15 +323,25 @@ beestat.component.card.three_d.prototype.decorate_drawing_pane_ = function(paren this.scene_.set_date(this.date_m_); // Manage width of the scene. - setTimeout(function() { - if (parent.getBoundingClientRect().width > 0) { - self.scene_.set_width(parent.getBoundingClientRect().width); - } - }, 0); + if (this.state_.width === undefined) { + setTimeout(function() { + if (parent.getBoundingClientRect().width > 0) { + self.state_.width = parent.getBoundingClientRect().width; + self.scene_.set_width(self.state_.width); + } + }, 0); + } else { + this.scene_.set_width(this.state_.width); + } + + if (this.state_.scene_camera_state !== undefined) { + this.scene_.set_camera_state(this.state_.scene_camera_state); + } beestat.dispatcher.removeEventListener('resize.three_d'); beestat.dispatcher.addEventListener('resize.three_d', function() { - self.scene_.set_width(parent.getBoundingClientRect().width); + self.state_.width = parent.getBoundingClientRect().width; + self.scene_.set_width(self.state_.width); }); }; diff --git a/js/component/scene.js b/js/component/scene.js index ddb2cf5..bcc7afd 100644 --- a/js/component/scene.js +++ b/js/component/scene.js @@ -65,7 +65,6 @@ beestat.component.scene.prototype.set_width = function(width) { this.camera_.updateProjectionMatrix(); this.renderer_.setSize(this.width_, this.height_); - this.renderer_.render(this.scene_, this.camera_); }; /** @@ -92,7 +91,7 @@ beestat.component.scene.prototype.decorate_ = function(parent) { this.height_ = 500; this.add_scene_(parent); - this.add_background_(parent); + // this.add_background_(parent); this.add_renderer_(parent); this.add_camera_(); this.add_controls_(parent); @@ -181,6 +180,9 @@ beestat.component.scene.prototype.add_renderer_ = function(parent) { this.renderer_ = new THREE.WebGLRenderer({ 'antialias': true }); + + this.renderer_.setSize(this.width_, this.height_); + // this.renderer_.setSize(window.innerWidth, window.innerHeight); // this.renderer_.shadowMap.enabled = true; // this.renderer_.shadowMap.autoUpdate = false; @@ -725,9 +727,9 @@ beestat.component.scene.prototype.update_ = function() { /** * Add a background. */ -beestat.component.scene.prototype.add_background_ = function() { - this.scene_.background = new THREE.Color(beestat.style.color.bluegray.dark); -} +// beestat.component.scene.prototype.add_background_ = function() { +// this.scene_.background = new THREE.Color(beestat.style.color.bluegray.dark); +// } @@ -995,3 +997,26 @@ beestat.component.scene.prototype.set_gradient = function(gradient) { return this; }; + +/** + * Get the state of the camera. + * + * @return {object} + */ +beestat.component.scene.prototype.get_camera_state = function() { + return this.camera_.matrix.toArray(); +}; + +/** + * Restore the state of the camera. + * + * @param {object} camera_state + */ +beestat.component.scene.prototype.set_camera_state = function(camera_state) { + this.camera_.matrix.fromArray(camera_state); + this.camera_.matrix.decompose( + this.camera_.position, + this.camera_.quaternion, + this.camera_.scale + ); +};