-
Notifications
You must be signed in to change notification settings - Fork 1
/
llama.html
executable file
·174 lines (119 loc) · 4.09 KB
/
llama.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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="three.js"></script>
<script type="text/javascript" src="dat.gui.min.js"></script>
<script type="text/javascript" src="libgif.js"></script>
<script src="TrackballControls.js"></script>
<style type="text/css">
.jsgif {
display: none;
}
</style>
</head>
<body style="background:#ececec; margin:0px; padding:0px" onmousemove="update()">
<img id="example2" src="llama.gif" rel:auto_play="1" width="467" height="375" rel:rubbable="1" />
<div id="container"></div>
<!-- ----- MAIN THREE.JS CODE ----- -->
<script type="text/javascript">
var sup2 = new SuperGif({ gif: document.getElementById('example2') } );
sup2.load();
llamacanvas = sup2.get_canvas();
var ictx=llamacanvas.getContext("2d");
var camera, scene, renderer, container;
var light, pointLight, geometry, mesh;
var uniforms, material;
var heightmap, diffTexture, dispTexture;
function start() {
container = document.getElementById( 'container' );
// --- WebGl render
try {
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.autoClear = false;
container.appendChild( renderer.domElement );
}
catch (e) {
alert(e);
}
scene = new THREE.Scene();
// --- Camera
var fov = 15; // camera field-of-view in degrees
var width = renderer.domElement.width;
var height = renderer.domElement.height;
var aspect = width / height; // view aspect ratio
camera = new THREE.PerspectiveCamera( fov, aspect );
camera.position.z = -600;
camera.position.y = -800;
camera.lookAt(scene.position);
camera.updateMatrix();
controls = new THREE.TrackballControls( camera, renderer.domElement );
controls.rotateSpeed = 3.0;
controls.zoomSpeed = 1.2;
controls.panSpeed = 0.8;
controls.noZoom = false;
controls.noPan = false;
controls.staticMoving = true;
controls.dynamicDampingFactor = 0.3;
controls.addEventListener( 'change', render );
// --- Lights
pointLight = new THREE.PointLight( 0xffffff, 1.0 );
scene.add( pointLight );
pointLight.position.set(0, 100, -200);
// MATERIAL
dispTexture = new THREE.Texture(llamacanvas);
var shader = THREE.ShaderLib[ "normalmap" ];
uniforms = THREE.UniformsUtils.clone( shader.uniforms );
uniforms[ "enableDisplacement" ] = { type: 'i', value: 1 };
uniforms[ "tDisplacement" ] = { type: 't', value: dispTexture };
uniforms[ "uDisplacementScale" ] = { type: 'f', value: 35 };
uniforms[ "enableDiffuse" ] = { type: 'i', value: 1 };
uniforms[ "tDiffuse" ].value = dispTexture;
uniforms[ "tNormal" ] = { type: 't', value: new THREE.ImageUtils.loadTexture( 'flat.png' )};
material = new THREE.ShaderMaterial( {
uniforms: uniforms,
vertexShader: shader.vertexShader,
fragmentShader: shader.fragmentShader,
lights: true,
side: THREE.DoubleSide
} );
// GEOMETRY
geometry = new THREE.PlaneGeometry(256, 200, 256, 200);
geometry.computeTangents();
mesh = new THREE.Mesh( geometry, material);
mesh.rotation.y = Math.PI;
scene.add(mesh);
setInterval("update()", 30);
update();
}
function update() {
dispTexture.needsUpdate = true;
render();
controls.update(); // trackball interaction
}
function render() {
renderer.clear();
renderer.render(scene, camera);
}
function log(n) {
console.log(n);
}
// GUI
var initDisp = function() {
this.scale = 25;
}
window.onload = function() {
var disp = new initDisp();
var gui = new dat.GUI();
var scaleVal = 25.0;
scControl = gui.add(disp, "scale", 0, 200);
scControl.onChange(function(value) {
scaleVal = value;
uniforms[ "uDisplacementScale" ].value = value;
});
start();
controls.update();
}
</script>
</body>
</html>