-
Notifications
You must be signed in to change notification settings - Fork 7
/
14-texturing-quad.html
71 lines (59 loc) · 1.94 KB
/
14-texturing-quad.html
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
<html>
<head>
<title>Texturing a quad</title>
<style>
body {
font-family: Monospace;
background-color: #f0f0f0;
margin: 0px;
overflow: hidden;
}
canvas {
width: 100%;
height: 100%;
}
</style>
<script src="lib/three.min.js"></script>
<script src="lib/stats.min.js"></script>
</head>
<body>
<script>
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setClearColor( 0xf0f0f0 );
document.body.appendChild( renderer.domElement );
var material, geometry, mesh;
var ourMap = THREE.ImageUtils.loadTexture( 'textures/brick_brownGrooved_1k_d.png' );
var material = new THREE.MeshBasicMaterial( { map: ourMap } );
geometry = new THREE.Geometry();
geometry.vertices.push( new THREE.Vector3( -2, 2, 0 ));
geometry.vertices.push( new THREE.Vector3( -2, -2, 0 ));
geometry.vertices.push( new THREE.Vector3( 2, -2, 0 ));
geometry.vertices.push( new THREE.Vector3( 2, 2, 0 ));
var uvs=[];
uvs.push( new THREE.Vector2(0.0, 0.5));
uvs.push( new THREE.Vector2(0.0, 0.0));
uvs.push( new THREE.Vector2(0.5, 0.0));
uvs.push( new THREE.Vector2(0.7, 0.7));
geometry.faces.push( new THREE.Face3( 0, 1, 2));
geometry.faceVertexUvs[0].push( [ uvs[0], uvs[1], uvs[2] ] );
geometry.faces.push( new THREE.Face3( 0, 2, 3));
geometry.faceVertexUvs[0].push( [ uvs[0], uvs[2], uvs[3] ] );
mesh = new THREE.Mesh(geometry, material);
scene.add( mesh );
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
document.body.appendChild( stats.domElement );
camera.position.z = 5;
function render() {
requestAnimationFrame(render);
stats.update();
renderer.render(scene, camera);
}
render();
</script>
</body>
</html>