|
|
|
|
|
|
|
|
|
|
|
|
|
|
private _v1 = new Vector3() |
|
|
private _v1 = new Vector3() |
|
|
private _v2 = new Vector3() |
|
|
private _v2 = new Vector3() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Refreshes the scene active camera near far values, based on the scene bounding box. |
|
|
* Refreshes the scene active camera near far values, based on the scene bounding box. |
|
|
* This is called automatically every time the camera is updated. |
|
|
* This is called automatically every time the camera is updated. |
|
|
|
|
|
|
|
|
const camera = this.mainCamera as ICamera |
|
|
const camera = this.mainCamera as ICamera |
|
|
if (!camera) return |
|
|
if (!camera) return |
|
|
if (camera.userData.autoNearFar === false) { |
|
|
if (camera.userData.autoNearFar === false) { |
|
|
camera.near = camera.userData.minNearPlane ?? 0.2 |
|
|
|
|
|
|
|
|
camera.near = camera.userData.minNearPlane ?? 0.5 |
|
|
camera.far = camera.userData.maxFarPlane ?? 1000 |
|
|
camera.far = camera.userData.maxFarPlane ?? 1000 |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// new way |
|
|
// new way |
|
|
const dist1 = Math.max(0.1, -this._v1.normalize().dot(camera.getWorldDirection(new Vector3()))) |
|
|
const dist1 = Math.max(0.1, -this._v1.normalize().dot(camera.getWorldDirection(new Vector3()))) |
|
|
const near = Math.max(camera.userData.minNearPlane ?? 0.2, dist1 * (dist - radius)) |
|
|
|
|
|
|
|
|
const near = Math.max(camera.userData.minNearPlane ?? 0.5, dist1 * (dist - radius)) |
|
|
const far = Math.min(Math.max(near + radius, dist1 * (dist + radius)), camera.userData.maxFarPlane ?? 1000) |
|
|
const far = Math.min(Math.max(near + radius, dist1 * (dist + radius)), camera.userData.maxFarPlane ?? 1000) |
|
|
|
|
|
|
|
|
// old way, has issues when panning very far from the camera target |
|
|
// old way, has issues when panning very far from the camera target |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Minimum Camera near plane |
|
|
* Minimum Camera near plane |
|
|
* @deprecated - use camera.userData.minNearPlane instead |
|
|
|
|
|
|
|
|
* @deprecated - use camera.minNearPlane instead |
|
|
*/ |
|
|
*/ |
|
|
get minNearDistance(): number { |
|
|
get minNearDistance(): number { |
|
|
console.error('minNearDistance is deprecated. Use camera.userData.minNearPlane instead') |
|
|
console.error('minNearDistance is deprecated. Use camera.userData.minNearPlane instead') |
|
|
return this.mainCamera.userData.minNearPlane ?? 0.02 |
|
|
return this.mainCamera.userData.minNearPlane ?? 0.02 |
|
|
} |
|
|
} |
|
|
/** |
|
|
/** |
|
|
* @deprecated - use camera.userData.minNearPlane instead |
|
|
|
|
|
|
|
|
* @deprecated - use camera.minNearPlane instead |
|
|
*/ |
|
|
*/ |
|
|
set minNearDistance(value: number) { |
|
|
set minNearDistance(value: number) { |
|
|
console.error('minNearDistance is deprecated. Use camera.userData.minNearPlane instead') |
|
|
console.error('minNearDistance is deprecated. Use camera.userData.minNearPlane instead') |