-
Notifications
You must be signed in to change notification settings - Fork 3
/
example7.html
161 lines (105 loc) · 4.05 KB
/
example7.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
<html>
<head>
<title>PixelBox Example 7</title>
<link rel="stylesheet" href="css/normalize.css"/>
<link rel="stylesheet" href="css/index.css"/>
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1"/>
<!-- THREE base includes -->
<script src="js/three.min.js"></script>
<!-- PixelBox include -->
<script src="js/pixelbox.min.js"></script>
<!-- OrbitControls from THREE's examples -->
<script src="js/OrbitControls.js"></script>
</head>
<body>
<a class="show-source" onclick="window.open('view-source:'+window.location.href.toString(),'_blank');">Source</a>
<span class="info">
<a href="https://github.com/kirilledelman/pixelbox" target="_blank">PixelBox</a>
by Kirill Edelman for <a href="http://threejs.org" target="_blank">three.js</a>
</span>
<script>
/*
This example shows how to use LinePath class
*/
document.addEventListener( 'DOMContentLoaded', function() {
if( !renderer.init() ) {
var err = "Your browser doesn't support WebGL";
alert( err );
console.error( err );
return;
} else {
console.log( "WebGL initialized" );
}
// load scene definition using THREE.PixelBoxAssets
assets.loadAssets( {
scenes: [ 'assets/example7.scene' ],
// when done, display scene
done: function() {
// instantiate our ExampleScene
exampleScene = new ExampleScene();
// set it as current for renderer
renderer.setScene( exampleScene );
} // end done:function
} ); // end assets.loadAssets
} ); // end document on ready
/*
ExampleScene extends THREE.PixelBoxScene
*/
function ExampleScene() {
// call superclass constructor
THREE.PixelBoxScene.call( this );
// get scene definition from assets cache
var sceneDef = assets.get( 'example7' );
// populate this scene with the definition
this.populateWith( sceneDef );
// add controls for easy preview
// various controls classes can be found in three.js examples/js/controls folder
this.controls = new THREE.OrbitControls( this.camera );
// scene definition contains THREE.PixelBox sprites named "cat1", "cat2"
// and a THREE.LinePath object named "cat_path"
// both are children of scene, so we can access them as this.cat1, this.cat2, and this.cat_path
// we're going to animate cat1 along the path
this.cat_path.tween( {
target: this.cat1, // cat is THREE.PixelBox instance, defined in example7.scene
from: 0.0, // starting point
to: 1.0, // ending point
orientToPath: true, // cat will face forward while moving along path
duration: 15, // time to reach end point
numLoops: Infinity, // keep walking indefinitely
autoReverse: true // automatically reverse direction each loop
} );
// and cat2 as well, but offset his position on the curve by half its length
this.cat_path.tween( {
target: this.cat2,
from: 0.5, // start halfway
to: 1.5, // finish 1 and a half way out
orientToPath: true,
duration: 15,
numLoops: Infinity,
autoReverse: true
} );
// scene definition also contains THREE.PixelBox sprite named "bird"
// and a THREE.LinePath object named "bird_path"
// we'll animate the bird along the path
this.bird_path.tween( {
target: this.bird,
from: 0,
to: 1,
orientToPath: true,
duration: 20,
numLoops: Infinity
} );
// tick function will update cats' heads each frame
this.tick = function( deltaTime ) {
// both cats will be looking at the bird
this.cat1.head.lookAtObject( this.bird );
this.cat2.head.lookAtObject( this.bird );
};
} // end ExampleScene constructor
// ExampleScene subclasses THREE.PixelBoxScene
ExampleScene.prototype = Object.create( THREE.PixelBoxScene.prototype );
ExampleScene.prototype.constructor = ExampleScene;
</script>
</body>
</html>