Hack MovieMaterial to support SimpleButton

Recently, i need to use a loaded swf as MovieMaterial. But i found that the simple button which i place on the timeline not working correctlly. So, i dig in the papervision code and found out why it is not working. In result, i found papervision will ignore the simple button since it is not interact with normal Mouse Event. Here is come gather a hack to deal with the simplebutton on moviematerial. Here is the hack

Edit the file VirtualMouse.as in org.papervision3d.core.utils.virtualmouse.

Find the place which ignore the SimpleButton

	// invalid target if in a SimpleButton
	if (currentTarget && currentParent is SimpleButton)
	{
		//log.debug("found SimpleButton - setting currentTarget to null");
		currentTarget = null;

change to

	// invalid target if in a SimpleButton
	if (currentTarget && currentParent is SimpleButton)
	{
		//log.debug("found SimpleButton - setting currentTarget to null");
		currentTarget = currentParent as InteractiveObject;

Hack to change the state of SimpleButton

1. Find the function

private function handleUpdate(event:Event):void

2. Add a var which hold the skin of the simpleButton.

var simpleButtonSkin:DisplayObject;

3. Add code here to swap the skin of SimpleButton upState and overState
// off of last target
if (!disabledEvents[MouseEvent.MOUSE_OUT]) {
if ( target is SimpleButton) {
simpleButtonSkin = (target as SimpleButton).overState;
(target as SimpleButton).overState = (target as SimpleButton).upState;
(target as SimpleButton).upState = swapSkin;
}

……..

// on to current target
if (!disabledEvents[MouseEvent.MOUSE_OVER]) {
if ( currentTarget is SimpleButton) {
simpleButtonSkin = (currentTarget as SimpleButton).upState;
(currentTarget as SimpleButton).upState = (currentTarget as SimpleButton).overState;
(currentTarget as SimpleButton).overState = swapSkin2;
}


……

if (!disabledEvents[MouseEvent.MOUSE_DOWN]) {
if ( currentTarget is SimpleButton) {
simpleButtonSkin = (currentTarget as SimpleButton).upState;
(currentTarget as SimpleButton).upState = (currentTarget as SimpleButton).downState;
(currentTarget as SimpleButton).downState = swapSkin3;
}

……

if (!disabledEvents[MouseEvent.MOUSE_UP]) {
if ( currentTarget is SimpleButton) {
simpleButtonSkin = (currentTarget as SimpleButton).upState;
(currentTarget as SimpleButton).upState = (currentTarget as SimpleButton).downState;
(currentTarget as SimpleButton).downState = swapSkin4;
}

…….

Here is the patched virtualmouse.as. Replace file in org.papervision3d.core.utils.virtualmouse.
Download virtualmouse.as

Custom Plane Class with resize function

You can not resize a plane in the original plane primitive in Papervision3D.

So, i write a new plane class extend original plane with a resizing function. This  conveients for dynamic changing the plane size.

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
package org.papervision3d.objects.primitives {
 
import org.papervision3d.core.proto.MaterialObject3D;
import org.papervision3d.core.math.NumberUV;
import org.papervision3d.core.geom.renderables.Vertex3D;
import org.papervision3d.core.geom.renderables.Triangle3D;
 
/**
* ...
* @author $(DefaultUser)
*/
public class PlaneDC extends org.papervision3d.objects.primitives.Plane {
 
public function PlaneDC( material:MaterialObject3D=null, width:Number=0, height:Number=0, segmentsW:Number=0, segmentsH:Number=0 ){
super( material, width, height, segmentsW, segmentsH );
}
 
/**
* Sets the scale along the local X axis as applied from the registration point of the object.
*/
public function setSize(width:Number,height:Number):void
{
 
var gridX    :Number = this.segmentsW;
var gridY    :Number = this.segmentsH;
var gridX1   :Number = gridX + 1;
var gridY1   :Number = gridY + 1;
 
var vertices :Array  = this.geometry.vertices;
var faces    :Array  = this.geometry.faces;
 
var textureX :Number = width /2;
var textureY :Number = height /2;
 
var iW       :Number = width / gridX;
var iH       :Number = height / gridY;
 
var count:Number = 0;
 
// Vertices
for( var ix:int = 0; ix < gridX + 1; ix++ )
{
for( var iy:int = 0; iy < gridY1; iy++ )
{
var x :Number = ix * iW - textureX;
var y :Number = iy * iH - textureY;
 
var v:Vertex3D = vertices[count];
 
v.x = x;
v.y = y;
 
count++;
}
}
 
count = 0;
 
// Faces
var uvA :NumberUV;
var uvC :NumberUV;
var uvB :NumberUV;
 
for(  ix = 0; ix < gridX; ix++ )
{
for(  iy= 0; iy < gridY; iy++ )
{
 
// Triangle A
var f:Triangle3D = faces[count];
 
// Triangle A
var a:Vertex3D = vertices[ ix     * gridY1 + iy     ];
var c:Vertex3D = vertices[ ix     * gridY1 + (iy+1) ];
var b:Vertex3D = vertices[ (ix+1) * gridY1 + iy     ];
 
uvA =  new NumberUV( ix     / gridX, iy     / gridY );
uvC =  new NumberUV( ix     / gridX, (iy+1) / gridY );
uvB =  new NumberUV( (ix+1) / gridX, iy     / gridY );
 
f.vertices = [ a, b, c ];
f.uv = [ uvA, uvB, uvC ];
 
// Triangle B
f = faces[count + 1];
 
a = vertices[ (ix+1) * gridY1 + (iy+1) ];
c = vertices[ (ix+1) * gridY1 + iy     ];
b = vertices[ ix     * gridY1 + (iy+1) ];
 
uvA =  new NumberUV( (ix+1) / gridX, (iy+1) / gridY );
uvC =  new NumberUV( (ix+1) / gridX, iy      / gridY );
uvB =  new NumberUV( ix      / gridX, (iy+1) / gridY );
 
f.vertices = [ a, b, c ];
f.uv = [ uvA, uvB, uvC ];
 
count += 2;
}
}
 
this.geometry.ready = true;
 
}
 
}
 
}