Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples: Clean up #13737

Merged
merged 2 commits into from
Apr 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 41 additions & 43 deletions examples/webgl_camera_cinematic.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,43 @@
margin: 0px;
overflow: hidden;
}
#info {
position: absolute;
top: 10px;
width: 100%;
text-align: center;
}
</style>
</head>
<body>

<div id="info">
<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> webgl - interactive cubes
</div>

<script src="../build/three.js"></script>

<script src="js/shaders/BokehShader2.js"></script>

<script src="js/cameras/CinematicCamera.js"></script>

<script src="js/libs/stats.min.js"></script>
<script src='js/libs/dat.gui.min.js'></script>

<script>

var container, stats;
var camera, scene, raycaster, renderer;
var camera, scene, raycaster, renderer, stats;

var mouse = new THREE.Vector2(), INTERSECTED;
var radius = 100, theta = 0;



init();
animate();

function init() {

container = document.createElement( 'div' );
document.body.appendChild( container );

var info = document.createElement( 'div' );
info.style.position = 'absolute';
info.style.top = '10px';
info.style.width = '100%';
info.style.textAlign = 'center';
info.innerHTML = '<a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> webgl - interactive cubes';
container.appendChild( info );
camera = new THREE.CinematicCamera( 60, window.innerWidth / window.innerHeight, 1, 1000 );
camera.setLens(5);
camera.position.set(2, 1, 500);
camera.setLens( 5 );
camera.position.set( 2, 1, 500 );

scene = new THREE.Scene();
scene.background = new THREE.Color( 0xf0f0f0 );
Expand All @@ -62,8 +58,7 @@
light.position.set( 1, 1, 1 ).normalize();
scene.add( light );


var geometry = new THREE.BoxGeometry( 20, 20, 20 );
var geometry = new THREE.BoxBufferGeometry( 20, 20, 20 );

for ( var i = 0; i < 1500; i ++ ) {

Expand All @@ -82,15 +77,13 @@
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild(renderer.domElement);
document.body.appendChild( renderer.domElement );

stats = new Stats();
container.appendChild( stats.dom );
document.body.appendChild( stats.dom );

document.addEventListener( 'mousemove', onDocumentMouseMove, false );



window.addEventListener( 'resize', onWindowResize, false );

var effectController = {
Expand Down Expand Up @@ -123,32 +116,39 @@

var matChanger = function( ) {

for (var e in effectController) {
if (e in camera.postprocessing.bokeh_uniforms)
camera.postprocessing.bokeh_uniforms[ e ].value = effectController[ e ];
for ( var e in effectController ) {

if ( e in camera.postprocessing.bokeh_uniforms ) {

camera.postprocessing.bokeh_uniforms[ e ].value = effectController[ e ];

}

}

camera.postprocessing.bokeh_uniforms[ 'znear' ].value = camera.near;
camera.postprocessing.bokeh_uniforms[ 'zfar' ].value = camera.far;
camera.setLens(effectController.focalLength, camera.frameHeight ,effectController.fstop, camera.coc);
effectController['focalDepth'] = camera.postprocessing.bokeh_uniforms["focalDepth"].value;
camera.setLens( effectController.focalLength, camera.frameHeight, effectController.fstop, camera.coc );
effectController[ 'focalDepth' ] = camera.postprocessing.bokeh_uniforms[ 'focalDepth' ].value;

};

//

var gui = new dat.GUI();

gui.add( effectController, "focalLength", 1, 135, 0.01 ).onChange( matChanger );
gui.add( effectController, "fstop", 1.8, 22, 0.01 ).onChange( matChanger );
gui.add( effectController, "focalDepth", 0.1, 100, 0.001 ).onChange( matChanger );
gui.add( effectController, "showFocus", true ).onChange( matChanger );
gui.add( effectController, 'focalLength', 1, 135, 0.01 ).onChange( matChanger );
gui.add( effectController, 'fstop', 1.8, 22, 0.01 ).onChange( matChanger );
gui.add( effectController, 'focalDepth', 0.1, 100, 0.001 ).onChange( matChanger );
gui.add( effectController, 'showFocus', true ).onChange( matChanger );

matChanger();

window.addEventListener( 'resize', onWindowResize, false );

}


function onWindowResize() {
function onWindowResize() {

camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
Expand All @@ -166,7 +166,6 @@

}


function animate() {

requestAnimationFrame( animate, renderer.domElement );
Expand Down Expand Up @@ -197,9 +196,8 @@
if ( intersects.length > 0 ) {

var targetDistance = intersects[ 0 ].distance;

//Using Cinematic camera focusAt method
camera.focusAt(targetDistance);

camera.focusAt( targetDistance ); // using Cinematic camera focusAt method

if ( INTERSECTED != intersects[ 0 ].object ) {

Expand All @@ -218,13 +216,13 @@

}

//

if(camera.postprocessing.enabled){
//rendering Cinematic Camera effects
camera.renderCinematic(scene, renderer);
}
if ( camera.postprocessing.enabled ) {

else {
camera.renderCinematic( scene, renderer );

} else {

scene.overrideMaterial = null;

Expand Down