123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
- <title>three.js webgl - loader callbacks</title>
- <style>
- body {
- margin: 0;
- font-family: Arial;
- overflow: hidden;
- }
- a {
- color: #ffffff;
- }
- #info {
- position: absolute;
- top: 0px;
- width: 100%;
- color: #ffffff;
- padding: 5px;
- font-family: Monospace;
- font-size: 13px;
- font-weight: bold;
- text-align: center;
- z-index: 1;
- }
- #menu {
- position: absolute;
- bottom: 20px;
- width: 100%;
- text-align: center;
- padding: 0;
- margin: 0;
- }
- button {
- color: rgb(255,255,255);
- background: transparent;
- border: 0px;
- padding: 5px 10px;
- cursor: pointer;
- }
- button:hover {
- background-color: rgba(0,255,255,0.5);
- }
- button:active {
- color: #000000;
- background-color: rgba(0,255,255,1);
- }
- .bond {
- width: 5px;
- height: 10px;
- background: #eee;
- display: block;
- }
- </style>
- </head>
- <body>
- <script src="../build/three.js"></script>
- <script src="js/controls/TrackballControls.js"></script>
- <div id="container"></div>
- <div id="info"><a href="http://threejs.org" target="_blank">three.js webgl</a> - molecules</div>
- <script>
- var camera, scene, renderer;
- var controls;
- init();
- animate();
- function init() {
- camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 5000 );
- camera.position.z = 3;
- scene = new THREE.Scene();
- var light = new THREE.HemisphereLight( 0xffffff, 0x000000 );
- light.position.set( 1, 1, 1 );
- scene.add( light );
- //
- renderer = new THREE.WebGLRenderer( { antialias: true } );
- renderer.setClearColor( 0x050505 );
- renderer.setSize( window.innerWidth, window.innerHeight );
- document.getElementById( 'container' ).appendChild( renderer.domElement );
- //
- controls = new THREE.TrackballControls( camera, renderer.domElement );
- controls.rotateSpeed = 0.5;
- controls.addEventListener( 'change', render );
- window.addEventListener( 'resize', onWindowResize, false );
- var textureLoader = new THREE.TextureLoader()
- textureLoader.load('textures/crate.gif', function(texture) {
- console.log('texture loaded')
- var material = new THREE.SpriteMaterial({ map: texture, color: 0xffffff, useScreenCoordinates: false})
- var sp = new THREE.Sprite(material);
- scene.add(sp)
- }, function(progress) {
- console.log('do we have progress?')
- })
- textureLoader.load('textures/404-texture-doesnt-exist.bmp', function(texture) {
- },function () {
- //progress callback
- }, function (error) {
- console.log('error caught - image not loaded')
- console.log(error)
- })
- }
- //
- function onWindowResize() {
- camera.aspect = window.innerWidth / window.innerHeight;
- camera.updateProjectionMatrix();
- renderer.setSize( window.innerWidth, window.innerHeight );
- render();
- }
- function animate() {
- requestAnimationFrame( animate );
- controls.update();
- render();
- }
- function render() {
- renderer.render( scene, camera );
- }
- </script>
- </body>
- </html>
|