-
Notifications
You must be signed in to change notification settings - Fork 1
/
FACEGEOM.as
88 lines (77 loc) · 1.95 KB
/
FACEGEOM.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
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
package
{
import away3d.containers.ObjectContainer3D;
import away3d.core.base.*;
import away3d.materials.Material;
import flash.geom.Vector3D;
import flash.utils.Dictionary;
public class FACEGEOM
{
/** @private */
private var _obj:ObjectContainer3D;
private var _faceLib:Vector.<Material>;
public var xMin:Number;
public var xMax:Number;
public var yMin:Number;
public var yMax:Number;
public var zMin:Number;
public var zMax:Number;
/**
* Store for all materials and bounds associated with each mesh face.
*/
public function FACEGEOM(obj:ObjectContainer3D)
{
_obj = obj;
xMin = yMin = zMin = Number.MAX_VALUE;
xMax = yMax = zMax = Number.MIN_VALUE;
_faceLib = new Vector.<Material>();
for each (var child:Mesh in _obj.children)
{
for each (var face:Face in child.faces)
{
for each (var v:Vertex in face.vertices)
{
if (v.x < xMin) xMin = v.x;
else if (v.x > xMax) xMax = v.x;
if (v.y < yMin) yMin = v.y;
else if (v.y > yMax) yMax = v.y;
if (v.z < zMin) zMin = v.z;
else if (v.z > zMax) zMax = v.z;
}
_faceLib.push(face.material);
}
}
}
public function get obj():ObjectContainer3D
{
return _obj;
}
public function set obj(value:ObjectContainer3D):void
{
if (_obj != value) _obj = value;
}
public function faceMaterial(i:uint):Material
{
return _faceLib[i];
}
/**
* Returns the center point of 3d object
*/
public function get centerPt():Vector3D
{
return new Vector3D(xMin + (xMax - xMin) / 2, yMin + (yMax - yMin) / 2, zMin + (zMax - zMin) / 2);
}
/**
* Returns max value of objectDepth, objectHeight and objectWidth
*/
public function get diametr():Number
{
var div0:Number = xMax - xMin;
var div1:Number = yMax - yMin;
var div2:Number = zMax - zMin;
if (div0 > div1) div1 = div0;
if (div1 > div2) div2 = div1;
return div2;
}
}
}