1
0
mirror of https://github.com/beestat/app.git synced 2025-05-24 02:14:03 -04:00

A few more fixes to scene rendering/resizing

This commit is contained in:
Jon Ziebell 2022-08-26 22:23:10 -04:00
parent 4fa7651189
commit 35d4d0b1f3
2 changed files with 47 additions and 11 deletions

View File

@ -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);
});
};

View File

@ -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
);
};