Skip to content

Commit

Permalink
refactored QuadtraticPath - filled emtpy methods
Browse files Browse the repository at this point in the history
  • Loading branch information
bbeaumont committed May 7, 2012
1 parent b46d7ae commit 2136216
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 52 deletions.
2 changes: 0 additions & 2 deletions src/away3d/extrusions/utils/PathUtils.as
Expand Up @@ -181,8 +181,6 @@

public static function calcCubicPosition(t:Number, ps:CubicPathSegment, out:Vector3D):Vector3D
{
// (1 - t)^3*start + 3*t*(1 - t)^2*control1 + 3*t^2*(1 - t)*control2 + t^3*end

var v:Vector3D = out || new Vector3D();

const td:Number = 1 - t;
Expand Down
96 changes: 46 additions & 50 deletions src/away3d/extrusions/utils/QuadraticPath.as
Expand Up @@ -21,15 +21,7 @@

public function QuadraticPath(aVectors:Vector.<Vector3D> = null)
{
if(aVectors!= null && aVectors.length < 3)
throw new Error("Path Vector.<Vector3D> must contain at least 3 Vector3D's");

_segments = new Vector.<IPathSegment>();

if(aVectors != null)
for(var i:int = 0; i<aVectors.length; i+=3)
_segments.push( new QuadraticPathSegment(aVectors[i], aVectors[i+1], aVectors[i+2]));

pointData = aVectors;
}


Expand Down Expand Up @@ -142,46 +134,7 @@
{
return _segments[indice];
}

/**
* removes a segment in the path according to id.
*
* @param index int. The index in path of the to be removed curvesegment
* @param join Boolean. If true previous and next segments coordinates are reconnected
*/
public function removeSegment(index:int, join:Boolean = false):void
{
if(_segments.length == 0 || _segments[index ] == null )
return;

if(join && index < _segments.length-1 && index>0){
var seg:QuadraticPathSegment = _segments[index] as QuadraticPathSegment;
var prevSeg:QuadraticPathSegment = _segments[index-1] as QuadraticPathSegment;
var nextSeg:QuadraticPathSegment = _segments[index+1] as QuadraticPathSegment;
prevSeg.pControl.x = (prevSeg.pControl.x+seg.pControl.x)*.5;
prevSeg.pControl.y = (prevSeg.pControl.y+seg.pControl.y)*.5;
prevSeg.pControl.z = (prevSeg.pControl.z+seg.pControl.z)*.5;
nextSeg.pControl.x = (nextSeg.pControl.x+seg.pControl.x)*.5;
nextSeg.pControl.y = (nextSeg.pControl.y+seg.pControl.y)*.5;
nextSeg.pControl.z = (nextSeg.pControl.z+seg.pControl.z)*.5;
prevSeg.pEnd.x = (seg.pStart.x + seg.pEnd.x)*.5;
prevSeg.pEnd.y = (seg.pStart.y + seg.pEnd.y)*.5;
prevSeg.pEnd.z = (seg.pStart.z + seg.pEnd.z)*.5;
nextSeg.pStart.x = prevSeg.pEnd.x;
nextSeg.pStart.y = prevSeg.pEnd.y;
nextSeg.pStart.z = prevSeg.pEnd.z;

/*if(_pathDebug != null)
_pathDebug.updateAnchorAt(index-1);
_pathDebug.updateAnchorAt(index+1);*/
}

if(_segments.length > 1){
_segments.splice(index, 1);
} else{
_segments = new Vector.<IPathSegment>();
}
}


/**
* handler will smooth the path using anchors as control vector of the PathSegments
Expand Down Expand Up @@ -312,27 +265,70 @@

public function set pointData(data:Vector.<Vector3D>):void
{
if(data!= null && data.length < 3)
throw new Error("Path Vector.<Vector3D> must contain at least 3 Vector3D's");

_segments = new Vector.<IPathSegment>();

if(data != null)
for(var i:int = 0; i<data.length; i+=3)
_segments.push( new QuadraticPathSegment(data[i], data[i+1], data[i+2]));
}


public function get worldAxis():Vector3D
{
return null;
return _worldAxis;
}


public function set worldAxis(value:Vector3D):void
{
_worldAxis = value;
}


public function remove(index:uint, join:Boolean = false):void
{
if(_segments.length == 0 || _segments[index ] == null )
return;

if(join && index < _segments.length-1 && index>0){
var seg:QuadraticPathSegment = _segments[index] as QuadraticPathSegment;
var prevSeg:QuadraticPathSegment = _segments[index-1] as QuadraticPathSegment;
var nextSeg:QuadraticPathSegment = _segments[index+1] as QuadraticPathSegment;
prevSeg.pControl.x = (prevSeg.pControl.x+seg.pControl.x)*.5;
prevSeg.pControl.y = (prevSeg.pControl.y+seg.pControl.y)*.5;
prevSeg.pControl.z = (prevSeg.pControl.z+seg.pControl.z)*.5;
nextSeg.pControl.x = (nextSeg.pControl.x+seg.pControl.x)*.5;
nextSeg.pControl.y = (nextSeg.pControl.y+seg.pControl.y)*.5;
nextSeg.pControl.z = (nextSeg.pControl.z+seg.pControl.z)*.5;
prevSeg.pEnd.x = (seg.pStart.x + seg.pEnd.x)*.5;
prevSeg.pEnd.y = (seg.pStart.y + seg.pEnd.y)*.5;
prevSeg.pEnd.z = (seg.pStart.z + seg.pEnd.z)*.5;
nextSeg.pStart.x = prevSeg.pEnd.x;
nextSeg.pStart.y = prevSeg.pEnd.y;
nextSeg.pStart.z = prevSeg.pEnd.z;

/*if(_pathDebug != null)
_pathDebug.updateAnchorAt(index-1);
_pathDebug.updateAnchorAt(index+1);*/
}

if(_segments.length > 1){
_segments.splice(index, 1);
} else{
_segments = new Vector.<IPathSegment>();
}
}


public function dispose():void
{
while (_segments.length > 0)
_segments[0].dispose();
_segments = null;
_worldAxis = null;
}
}
}

0 comments on commit 2136216

Please sign in to comment.