MCPcopy
hub / github.com/ampproject/amphtml / setupCameraForObject_

Method setupCameraForObject_

3p/3d-gltf/viewer.js:205–227  ·  view source on GitHub ↗

* Camera is set to be not too far or near in terms of object's size. * * We are positioning camera on a ray coming from center (C) * of bounding box to its corner with max coordinates (M), * and outside bbox to the length of CM * CAMERA_DISTANCE_FACTOR. * * It may look weird for ob

(object)

Source from the content-addressed store, hash-verified

203 * @param {!THREE.Object3D} object
204 * @private */
205 setupCameraForObject_(object) {
206 const center = new THREE.Vector3();
207 const size = new THREE.Vector3();
208 const bbox = new THREE.Box3();
209 bbox.setFromObject(object);
210 bbox.getCenter(center);
211 bbox.getSize(size);
212
213 const sizeLength = size.length();
214 this.camera_.far = sizeLength * CAMERA_FAR_FACTOR;
215 this.camera_.near = sizeLength * CAMERA_NEAR_FACTOR;
216 this.camera_.position.lerpVectors(
217 center,
218 bbox.max,
219 1 + CAMERA_DISTANCE_FACTOR
220 );
221 this.camera_.lookAt(center);
222
223 this.camera_.updateProjectionMatrix();
224 this.camera_.updateMatrixWorld();
225
226 this.controls_.target.copy(center);
227 }
228
229 /** @private */
230 loadObject_() {

Callers 1

loadObject_Method · 0.95

Calls 2

lengthMethod · 0.80
getSizeMethod · 0.45

Tested by

no test coverage detected