提交 253852b6 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #11717 from Mugen87/dev2

TGALoader: Refactoring
此差异已折叠。
<!DOCTYPE html>
<!--
@author Daosheng Mu / https://github.com/DaoshengMu/
-->
<html>
<html lang="en">
<head>
<title>three.js webgl - materials - tga texture</title>
<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;
background:#777;
padding:0;
margin:0;
overflow:hidden;
}
#info {
position: absolute;
top: 0px;
width: 100%;
color: #ffffff;
padding: 5px;
font-family:Monospace;
font-size:13px;
text-align:center;
}
background-color: #fff;
margin: 0px;
padding: 0px;
overflow: hidden;
a {
color: #ffffff;
}
</style>
</head>
<body>
<div id="info">
<a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> - tga texture example
<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - TGA texture example by <a href="https://github.com/DaoshengMu/" target="_blank" rel="noopener">Daosheng Mu</a>
</div>
<script src="../build/three.js"></script>
<script src="js/controls/OrbitControls.js"></script>
<script src="js/loaders/TGALoader.js"></script>
<script src="js/Detector.js"></script>
......@@ -35,55 +43,39 @@
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;
var camera, scene, renderer, stats;
init();
animate();
function init() {
container = document.createElement( 'div' );
var container = document.createElement( 'div' );
document.body.appendChild( container );
renderer = new THREE.WebGLRenderer( { antialias: true } );
camera = new THREE.PerspectiveCamera( 35, SCREEN_WIDTH / SCREEN_HEIGHT, 10, 2000 );
camera.position.z = 200;
camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 2000 );
camera.position.set( 0, 50, 250 );
scene = new THREE.Scene();
scene.add( new THREE.AmbientLight( 0xffffff, 0.4 ) );
var light = new THREE.DirectionalLight( 0xffffff, 1 );
light.position.set( 1, 1, 1 );
scene.add( light );
//
var loader = new THREE.TGALoader();
var geometry = new THREE.BoxBufferGeometry( 50, 50, 50 );
// add box 1 - grey8 texture
var texture1 = loader.load( 'textures/crate_grey8.tga' );
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.position.x = - 50;
scene.add( mesh1 );
// add box 2 - tga texture
var texture2 = loader.load( 'textures/crate_color8.tga' );
var texture2 = loader.load( 'textures/crate_color8.tga' );
var material2 = new THREE.MeshPhongMaterial( { color: 0xffffff, map: texture2 } );
var mesh2 = new THREE.Mesh( geometry, material2 );
......@@ -91,26 +83,43 @@
scene.add( mesh2 );
// RENDERER
//
var ambientLight = new THREE.AmbientLight( 0xffffff, 0.4 );
scene.add( ambientLight );
var light = new THREE.DirectionalLight( 0xffffff, 1 );
light.position.set( 1, 1, 1 );
scene.add( light );
//
renderer.setClearColor( 0xf2f7ff );
var controls = new THREE.OrbitControls( camera );
//
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
renderer.domElement.style.position = "relative";
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
// STATS1
//
stats = new Stats();
container.appendChild( stats.dom );
document.addEventListener( 'mousemove', onDocumentMouseMove, false );
//
window.addEventListener( 'resize', onWindowResize, false );
}
function onDocumentMouseMove( event ) {
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
mouseX = ( event.clientX - windowHalfX );
mouseY = ( event.clientY - windowHalfY );
renderer.setSize( window.innerWidth, window.innerHeight );
}
......@@ -126,10 +135,6 @@
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.render( scene, camera );
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册