mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-11-26 23:44:56 +01:00
151 lines
3.7 KiB
HTML
Executable File
151 lines
3.7 KiB
HTML
Executable File
<!DOCTYPE html>
|
|
<!--
|
|
@author Daosheng Mu / https://github.com/DaoshengMu/
|
|
-->
|
|
<html>
|
|
<head>
|
|
<title>three.js webgl - materials - tga texture</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 {
|
|
color: #000;
|
|
font-family:Monospace;
|
|
font-size:13px;
|
|
text-align:center;
|
|
|
|
background-color: #fff;
|
|
margin: 0px;
|
|
padding: 0px;
|
|
overflow: hidden;
|
|
}
|
|
|
|
#stats { position: absolute; top:0; left: 0 }
|
|
#stats #fps { background: transparent !important }
|
|
#stats #fps #fpsText { color: #777 !important }
|
|
#stats #fps #fpsGraph { display: none }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="info">
|
|
<a href="http://threejs.org" target="_blank">three.js</a> - tga texture example
|
|
</div>
|
|
<script src="../build/three.min.js"></script>
|
|
<script src="js/loaders/TGALoader.js"></script>
|
|
|
|
<script src="js/Detector.js"></script>
|
|
<script src="js/libs/stats.min.js"></script>
|
|
|
|
<script>
|
|
|
|
if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
|
|
|
|
var SCREEN_WIDTH = window.innerWidth;
|
|
var SCREEN_HEIGHT = window.innerHeight;
|
|
|
|
var container,stats;
|
|
|
|
var camera, scene, renderer;
|
|
|
|
var mouseX = 0, mouseY = 0;
|
|
|
|
var windowHalfX = window.innerWidth / 2;
|
|
var windowHalfY = window.innerHeight / 2;
|
|
|
|
init();
|
|
animate();
|
|
|
|
function init() {
|
|
|
|
container = document.createElement( 'div' );
|
|
document.body.appendChild( container );
|
|
|
|
renderer = new THREE.WebGLRenderer( { antialias: true } );
|
|
|
|
camera = new THREE.PerspectiveCamera( 35, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 25000 );
|
|
camera.position.z = 200;
|
|
|
|
scene = new THREE.Scene();
|
|
|
|
var light = new THREE.DirectionalLight( 0xffffff, 2 );
|
|
light.position.set( 1, 1, 1 );
|
|
scene.add( light );
|
|
|
|
var loader = new THREE.TGALoader();
|
|
|
|
// add box 1 - grey8 texture
|
|
var texture1 = loader.load( 'textures/crate_grey8.tga' );
|
|
var material1 = new THREE.MeshPhongMaterial( { color: 0xffffff, map: texture1 } );
|
|
|
|
var geometry = new THREE.BoxGeometry( 50, 50, 50 );
|
|
var mesh1 = new THREE.Mesh( geometry, material1 );
|
|
mesh1.rotation.x = -Math.PI / 2;
|
|
mesh1.position.x = - 50;
|
|
|
|
scene.add( mesh1 );
|
|
|
|
// add box 2 - tga texture
|
|
var texture2 = loader.load( 'textures/crate_color8.tga' );
|
|
var material2 = new THREE.MeshPhongMaterial( { color: 0xffffff, map: texture2 } );
|
|
|
|
var mesh2 = new THREE.Mesh( geometry, material2 );
|
|
mesh2.rotation.x = -Math.PI / 2;
|
|
mesh2.position.x = 50;
|
|
|
|
scene.add( mesh2 );
|
|
|
|
// RENDERER
|
|
|
|
renderer.setClearColor( 0xf2f7ff );
|
|
renderer.setPixelRatio( window.devicePixelRatio );
|
|
renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
|
|
renderer.autoClear = false;
|
|
|
|
renderer.domElement.style.position = "relative";
|
|
container.appendChild( renderer.domElement );
|
|
|
|
// STATS1
|
|
stats = new Stats();
|
|
container.appendChild( stats.domElement );
|
|
|
|
document.addEventListener( 'mousemove', onDocumentMouseMove, false );
|
|
|
|
}
|
|
|
|
function onDocumentMouseMove(event) {
|
|
|
|
mouseX = ( event.clientX - windowHalfX );
|
|
mouseY = ( event.clientY - windowHalfY );
|
|
|
|
}
|
|
|
|
|
|
function animate() {
|
|
|
|
requestAnimationFrame( animate );
|
|
|
|
render();
|
|
stats.update();
|
|
|
|
}
|
|
|
|
function render() {
|
|
|
|
camera.position.x += ( mouseX - camera.position.x ) * .05;
|
|
camera.position.y = THREE.Math.clamp( camera.position.y + ( - ( mouseY - 200 ) - camera.position.y ) * .05, 50, 1000 );
|
|
|
|
camera.lookAt( scene.position );
|
|
|
|
renderer.enableScissorTest( false );
|
|
renderer.clear();
|
|
renderer.enableScissorTest( true );
|
|
|
|
renderer.setScissor( 0, 0, SCREEN_WIDTH - 2, SCREEN_HEIGHT );
|
|
renderer.render( scene, camera );
|
|
|
|
}
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|