w3d2
by Leoooo
HTML
<div id="info"> Hw2 <a href="javascript:toggleCamera()">helper</a>
<br>
<button id="tView" style="width:20%">Toggle Turn</button>
<input type=range min=0 max=1 step=0.1 id='intensity'> intensity <br>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/107/three.min.js"></script>
<script src="https://threejs.org/examples/js/controls/OrbitControls.js">
</script>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
CSS
#info {
position: absolute;
top: 2%;
width: 100%;
padding: 10px;
text-align: center;
color: #ffff00
}
body {
overflow: hidden;
}
JavaScript
var useCamera1 = false;
var lightsOff = false;
$('#intensity').change ( function() {
console.log ( $(this).val() );
light.intensity = $(this).val();
})
$('#tView').click(function() {
// toggleCamera();
lightsOff = !lightsOff;
if (lightsOff) {
light.intensity = 0;
light2.intensity = 0;
} else {
light.intensity = .5;
light2.intensity = .5;
}
});
function toggleCamera() {
useCamera1 = !useCamera1;
}
var scene, renderer, camera;
var camera1;
init();
animate();
function init() {
scene = new THREE.Scene();
renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x888888);
document.body.appendChild(renderer.domElement);
camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 1, 10000);
camera.position.z = 500;
controls = new THREE.OrbitControls(camera, renderer.domElement);
var gridXZ = new THREE.GridHelper(200, 20, 'red', 'white');
//scene.add(gridXZ);
window.addEventListener('resize', onWindowResize, false);
//////////////////////////////////////////////////////////////////////////////
let wall = new THREE.Mesh(new THREE.BoxGeometry(10, 60, 100), new THREE.MeshPhongMaterial())
scene.add(wall);
wall.position.y = 30;
let loader = new THREE.TextureLoader();
loader.crossOrigin = '';
texture = loader.load('https://i.imgur.com/DrvlmNW.jpg?1');
texture.repeat.set (2,2);
texture.wrapS = texture.wrapT = true;
let floor = new THREE.Mesh(new THREE.PlaneGeometry(200, 200), new THREE.MeshPhongMaterial({
side: THREE.DoubleSide,
map: texture
}))
scene.add(floor)
floor.rotation.x = -Math.PI / 2
camera1 = new THREE.PerspectiveCamera(60, 1, 1, 1000);
camera1.position.set(-100, 160, 0);
camera1.lookAt(new THREE.Vector3(0, 60, 0));
/////////////////////////////////////////
light = new THREE.PointLight(0xffffff, 1,270);
light.position.set(80, 150, 0);
scene.add(light);
light2 = new...