-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
82 lines (70 loc) · 2.65 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>Memory Leak Example</title>
<style>
body { margin: 0; }
canvas { width: 100%; height: 100% }
</style>
</head>
<body>
<script src="./three.js"></script>
<script>
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 1);
document.body.appendChild( renderer.domElement );
var camera = new THREE.PerspectiveCamera( 30, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.x = 0;
camera.position.y = 0;
camera.position.z = 500;
var scene = new THREE.Scene();
let imageSize = 100;
let meshArray = [];
let frameCount = 0;
function animate() {
requestAnimationFrame( animate );
renderer.render( scene, camera );
frameCount += 1;
if(!(frameCount%60)){
console.log("Creating Image!");
renderImage();
}
if(!((frameCount%60)-30) && frameCount > 60){
console.log("Removing Image!");
disposeImage();
}
}
animate();
function disposeImage() {
garbageCollection(meshArray[0]);
meshArray.splice(0,1);
}
function garbageCollection(mesh) {
scene.remove(mesh);
mesh.geometry.dispose();
mesh.geometry = undefined;
mesh.material.map.dispose();
mesh.material.map = undefined;
mesh.material.dispose();
mesh.material = undefined;
mesh = undefined;
}
function renderImage() {
let loader = new THREE.TextureLoader();
loader.crossOrigin = "Anonymous";
loader.load( 'environment-logo.jpg', function ( texture ) {
let material = new THREE.MeshBasicMaterial( { map: texture, overdraw: 0.5 } );
let geometry = new THREE.PlaneGeometry(imageSize, imageSize, 1, 1);
let mesh = new THREE.Mesh(geometry,material);
mesh.geometry.computeBoundingBox();
mesh.position.set(0,0,10);
mesh.scale.set(1, 1, 1);
scene.add(mesh);
meshArray.push(mesh);
});
}
</script>
</body>
</html>