1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
<script type="text/javascript" src="three.js"></script>
<script type="text/javascript" src="OBJLoader.js"></script>
<script type="text/javascript" src="TrackballControls.js"></script>
<script>
var camera, scene, renderer, control, controls, light;
var cross, container;
var width, height;
init();
animate();
render();
function init() {
width =window.innerWidth;
height = window.innerHeight;
container = document.createElement('div');
container.id = 'container';
document.getElementById("A6").appendChild( container );
renderer = new THREE.WebGLRenderer({ antialias: false });
renderer.sortObjects = false;
renderer.setSize( width, height );
container.appendChild( renderer.domElement );
camera = new THREE.PerspectiveCamera( 70, width / height, 1, 15000 );
camera.position.set( 2500, 250, 2500 );
camera.lookAt( new THREE.Vector3( 0, 200, 0 ) );
controls = new THREE.TrackballControls( camera, container );
controls.rotateSpeed = 2.0;
controls.zoomSpeed = 2.5;
controls.panSpeed = 2.8;
controls.noZoom = false;
controls.noPan = false;
controls.staticMoving = true;
controls.dynamicDampingFactor = 0.3;
controls.keys = [ 65, 83, 68 ];
controls.addEventListener( 'change', render );
scene = new THREE.Scene();
cross = new THREE.GridHelper( 6500, 50 );
scene.add(cross);
light = new THREE.DirectionalLight( 0xf5f5f5, 2 );
light.position.set( 1, 1, 1 );
scene.add( light );
light = new THREE.DirectionalLight( 0x808080 );
light.position.set( -1, -1, -1 );
scene.add( light );
var textureobj = new THREE.Texture();
var loader = new THREE.ImageLoader();
loader.load('alu.jpg', function ( image ) {
textureobj.image = image;
textureobj.needsUpdate = true;
render();
} );
var loader = new THREE.OBJLoader();
loader.load('obj/635.obj', function ( object ) {
object.traverse( function ( child ) {
if ( child instanceof THREE.Mesh ) {
child.material.map = textureobj;
}
} );
var oldScale = new THREE.Vector3();
oldScale.copy(object.scale);object.rotation.x=-90*Math.PI/180;object.position.x=10+80/2;object.scale.z=oldScale.z * 9.9;
scene.add( object );
//control.attach(object);
//scene.add(control);
render();
} );
window.addEventListener( 'resize', onWindowResize, false );
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
controls.handleResize();
render();
}
function animate() {
requestAnimationFrame( animate );
controls.update();;
}
function render() {
renderer.render( scene, camera );
}
</script> |
Partager