Skip to content

Commit

Permalink
Improve furniture preview (misskey-dev#5328)
Browse files Browse the repository at this point in the history
* Improve furniture preview

* improve calc method

* camera.aspectいらないことに気付いた

* refactor & go camera far away

* 対角線の長さで計算するように

* 対角線の計算にhypot()を使用

Co-Authored-By: Aya Morisawa <AyaMorisawa4869@gmail.com>
  • Loading branch information
2 people authored and mei23 committed Aug 23, 2019
1 parent b161302 commit dc6db42
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/client/app/common/views/pages/room/preview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export default Vue.extend({
data() {
return {
selected: null,
objectHeight: 0
objectHeight: 0,
orbitRadius: 5
};
},
Expand Down Expand Up @@ -57,9 +58,9 @@ export default Vue.extend({
const timer = Date.now() * 0.0004;
requestAnimationFrame(render);
camera.position.y = 2 + this.objectHeight / 2;
camera.position.z = Math.cos(timer) * 10;
camera.position.x = Math.sin(timer) * 10;
camera.position.y = Math.sin(Math.PI / 6) * this.orbitRadius; // Math.PI / 6 => 30deg
camera.position.z = Math.cos(timer) * this.orbitRadius;
camera.position.x = Math.sin(timer) * this.orbitRadius;
camera.lookAt(new THREE.Vector3(0, this.objectHeight / 2, 0));
renderer.render(scene, camera);
};
Expand Down Expand Up @@ -89,6 +90,13 @@ export default Vue.extend({
});
const objectBoundingBox = new THREE.Box3().setFromObject(obj);
this.objectHeight = objectBoundingBox.max.y - objectBoundingBox.min.y;
const objectWidth = objectBoundingBox.max.x - objectBoundingBox.min.x;
const objectDepth = objectBoundingBox.max.z - objectBoundingBox.min.z;
const horizontal = Math.hypot(objectWidth, objectDepth) / camera.aspect;
this.orbitRadius = Math.max(horizontal, this.objectHeight) * camera.zoom * 0.625 / Math.tan(camera.fov * 0.5 * (Math.PI / 180));
scene.add(obj);
};
Expand Down

0 comments on commit dc6db42

Please sign in to comment.