-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial change * mrdoob approves * updated example * update screenshot
- Loading branch information
Showing
4 changed files
with
55 additions
and
189 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { BackSide, Mesh, MeshBasicMaterial, SphereGeometry, Vector3 } from 'three'; | ||
|
||
/** | ||
* A ground-projected skybox. The height is how far the camera that took the photo was above the ground - | ||
* a larger value will magnify the downward part of the image. By default the object is centered at the camera, | ||
* so it is often helpful to set skybox.position.y = height to put the ground at the origin. Set the radius | ||
* large enough to ensure your user's camera stays inside. | ||
*/ | ||
|
||
class GroundedSkybox extends Mesh { | ||
|
||
constructor( map, height, radius, resolution = 128 ) { | ||
|
||
if ( height <= 0 || radius <= 0 || resolution <= 0 ) { | ||
|
||
throw new Error( 'GroundedSkybox height, radius, and resolution must be positive.' ); | ||
|
||
} | ||
|
||
const geometry = new SphereGeometry( radius, 2 * resolution, resolution ); | ||
|
||
const pos = geometry.getAttribute( 'position' ); | ||
const tmp = new Vector3(); | ||
|
||
for ( let i = 0; i < pos.count; ++ i ) { | ||
|
||
tmp.fromBufferAttribute( pos, i ); | ||
if ( tmp.y < 0 ) { | ||
|
||
// Smooth out the transition from flat floor to sphere: | ||
const y1 = - height * 3 / 2; | ||
const f = | ||
tmp.y < y1 ? - height / tmp.y : ( 1 - tmp.y * tmp.y / ( 3 * y1 * y1 ) ); | ||
tmp.multiplyScalar( f ); | ||
tmp.toArray( pos.array, 3 * i ); | ||
|
||
} | ||
|
||
} | ||
|
||
pos.needsUpdate = true; | ||
|
||
super( geometry, new MeshBasicMaterial( { map, side: BackSide } ) ); | ||
|
||
} | ||
|
||
} | ||
|
||
export { GroundedSkybox }; |
Binary file modified
BIN
-23.6 KB
(12%)
examples/screenshots/webgl_materials_envmaps_groundprojected.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters