-
Notifications
You must be signed in to change notification settings - Fork 56
/
PickingTutorialListing02.as
60 lines (48 loc) · 1.89 KB
/
PickingTutorialListing02.as
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
package
{
import away3d.entities.Mesh;
import away3d.events.MouseEvent3D;
import away3d.materials.ColorMaterial;
import away3d.primitives.CubeGeometry;
import away3d.primitives.SphereGeometry;
public class PickingTutorialListing02 extends PickingTutorialListingBase
{
public function PickingTutorialListing02() {
super();
}
private var _inactiveMaterial:ColorMaterial;
private var _activeMaterial:ColorMaterial;
override protected function onSetup():void {
_cameraController.panAngle = -63;
_cameraController.tiltAngle = 10;
// Init materials.
_activeMaterial = new ColorMaterial( 0xFF0000 );
_activeMaterial.lightPicker = _lightPicker;
_inactiveMaterial = new ColorMaterial( 0xCCCCCC );
_inactiveMaterial.lightPicker = _lightPicker;
var disabledMaterial:ColorMaterial = new ColorMaterial( 0x666666 );
disabledMaterial.lightPicker = _lightPicker;
// Create 2 objects.
var cube:Mesh = new Mesh( new CubeGeometry(), disabledMaterial );
cube.x = -75;
_view.scene.addChild( cube );
var sphere:Mesh = new Mesh( new SphereGeometry(), _inactiveMaterial );
sphere.x = 75;
_view.scene.addChild( sphere );
// Enable mouse interactivity.
cube.mouseEnabled = true;
sphere.mouseEnabled = true;
// Attach mouse event listeners.
// cube.addEventListener( MouseEvent3D.MOUSE_OVER, onObjectMouseOver ); // By attaching no listeners to the object, it simply occludes picking ( if mouseEnabled = true ).
// cube.addEventListener( MouseEvent3D.MOUSE_OUT, onObjectMouseOut );
sphere.addEventListener( MouseEvent3D.MOUSE_OVER, onObjectMouseOver );
sphere.addEventListener( MouseEvent3D.MOUSE_OUT, onObjectMouseOut );
}
private function onObjectMouseOver( event:MouseEvent3D ):void {
event.target.material = _activeMaterial;
}
private function onObjectMouseOut( event:MouseEvent3D ):void {
event.target.material = _inactiveMaterial;
}
}
}