Skip to content

Commit

Permalink
correct fitto of first-person
Browse files Browse the repository at this point in the history
  • Loading branch information
yomotsu committed May 3, 2020
1 parent 6663412 commit b94a572
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion examples/first-person.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<button onclick="cameraControls.zoom( -camera.zoom / 2, true )">zoom `- camera.zoom / 2`</button>
<br>
<button onclick="cameraControls.moveTo( 3, 5, 2, true )">move to( 3, 5, 2 )</button>
<button onclick="cameraControls.fitTo( mesh, true )">fit to the bounding box of the mesh</button>
<button onclick="customFitTo()">fit to the bounding box of the mesh</button>
<button onclick="cameraControls.reset( true )">reset</button>
</div>

Expand Down Expand Up @@ -87,6 +87,26 @@
}

} )();


mesh.geometry.computeBoundingBox();
const meshBBSize = mesh.geometry.boundingBox.getSize( new THREE.Vector3() );
const meshBBWidth = meshBBSize.x;
const meshBBHeight = meshBBSize.y;
const meshBBDepth = meshBBSize.z;

function customFitTo() {

const distanceToFit = cameraControls.getDistanceToFit( meshBBWidth, meshBBHeight, meshBBDepth );
cameraControls.moveTo(
mesh.position.x,
mesh.position.y,
mesh.position.z + distanceToFit,
true
);
cameraControls.rotateTo( 0, 90 * THREE.Math.DEG2RAD, true );

}
</script>

</body>
Expand Down

0 comments on commit b94a572

Please sign in to comment.