You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
143 lines
3.5 KiB
143 lines
3.5 KiB
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<title>three.js webgl - helpers</title>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
|
|
<style>
|
|
body {
|
|
margin: 0px;
|
|
background-color: #000000;
|
|
overflow: hidden;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<script src="../build/three.js"></script>
|
|
|
|
<script src="js/loaders/GLTFLoader.js"></script>
|
|
|
|
<script>
|
|
|
|
var scene, renderer;
|
|
var camera, light;
|
|
var fnh, vnh;
|
|
|
|
init();
|
|
animate();
|
|
|
|
function init() {
|
|
|
|
renderer = new THREE.WebGLRenderer();
|
|
renderer.setPixelRatio( window.devicePixelRatio );
|
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
|
document.body.appendChild( renderer.domElement );
|
|
|
|
//
|
|
|
|
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000 );
|
|
camera.position.z = 400;
|
|
|
|
scene = new THREE.Scene();
|
|
|
|
light = new THREE.PointLight();
|
|
light.position.set( 200, 100, 150 );
|
|
scene.add( light );
|
|
|
|
scene.add( new THREE.PointLightHelper( light, 15 ) );
|
|
|
|
var gridHelper = new THREE.GridHelper( 400, 40, 0x0000ff, 0x808080 );
|
|
gridHelper.position.y = - 150;
|
|
gridHelper.position.x = - 150;
|
|
scene.add( gridHelper );
|
|
|
|
var polarGridHelper = new THREE.PolarGridHelper( 200, 16, 8, 64, 0x0000ff, 0x808080 );
|
|
polarGridHelper.position.y = - 150;
|
|
polarGridHelper.position.x = 200;
|
|
scene.add( polarGridHelper );
|
|
|
|
var loader = new THREE.GLTFLoader();
|
|
loader.load( 'models/gltf/LeePerrySmith/LeePerrySmith.glb', function ( gltf ) {
|
|
|
|
var mesh = gltf.scene.children[ 0 ];
|
|
|
|
var group = new THREE.Group();
|
|
group.scale.multiplyScalar( 50 );
|
|
scene.add( group );
|
|
|
|
// To make sure that the matrixWorld is up to date for the boxhelpers
|
|
group.updateMatrixWorld( true );
|
|
|
|
group.add( mesh );
|
|
|
|
vnh = new THREE.VertexNormalsHelper( mesh, 5 );
|
|
scene.add( vnh );
|
|
|
|
scene.add( new THREE.BoxHelper( mesh ) );
|
|
|
|
var wireframe = new THREE.WireframeGeometry( mesh.geometry );
|
|
var line = new THREE.LineSegments( wireframe );
|
|
line.material.depthTest = false;
|
|
line.material.opacity = 0.25;
|
|
line.material.transparent = true;
|
|
line.position.x = 4;
|
|
group.add( line );
|
|
scene.add( new THREE.BoxHelper( line ) );
|
|
|
|
var edges = new THREE.EdgesGeometry( mesh.geometry );
|
|
var line = new THREE.LineSegments( edges );
|
|
line.material.depthTest = false;
|
|
line.material.opacity = 0.25;
|
|
line.material.transparent = true;
|
|
line.position.x = - 4;
|
|
group.add( line );
|
|
scene.add( new THREE.BoxHelper( line ) );
|
|
|
|
scene.add( new THREE.BoxHelper( group ) );
|
|
scene.add( new THREE.BoxHelper( scene ) );
|
|
|
|
|
|
} );
|
|
|
|
//
|
|
|
|
window.addEventListener( 'resize', onWindowResize, false );
|
|
|
|
}
|
|
|
|
function onWindowResize() {
|
|
|
|
camera.aspect = window.innerWidth / window.innerHeight;
|
|
camera.updateProjectionMatrix();
|
|
|
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
|
}
|
|
|
|
function animate() {
|
|
|
|
requestAnimationFrame( animate );
|
|
|
|
var time = - performance.now() * 0.0003;
|
|
|
|
camera.position.x = 400 * Math.cos( time );
|
|
camera.position.z = 400 * Math.sin( time );
|
|
camera.lookAt( scene.position );
|
|
|
|
light.position.x = Math.sin( time * 1.7 ) * 300;
|
|
light.position.y = Math.cos( time * 1.5 ) * 400;
|
|
light.position.z = Math.cos( time * 1.3 ) * 300;
|
|
|
|
if ( fnh ) fnh.update();
|
|
if ( vnh ) vnh.update();
|
|
|
|
renderer.render( scene, camera );
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|