Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional features for segments #721

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/away3d/entities/SegmentSet.as
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package away3d.entities
package away3d.entities
{
import away3d.arcane;
import away3d.animators.IAnimator;
Expand All @@ -14,6 +14,7 @@
import away3d.primitives.LineSegment;
import away3d.primitives.data.Segment;
import away3d.library.assets.AssetType;
import flash.display.BlendMode;

import flash.display3D.Context3D;
import flash.display3D.Context3DVertexBufferFormat;
Expand Down Expand Up @@ -53,6 +54,7 @@

_segments = new Dictionary();
material = new SegmentMaterial();
material.blendMode = BlendMode.LAYER;
}

/**
Expand Down Expand Up @@ -248,7 +250,10 @@
var startR:Number = segment._startR, startG:Number = segment._startG, startB:Number = segment._startB;
var endR:Number = segment._endR, endG:Number = segment._endG, endB:Number = segment._endB;
var index:uint = segment.index;
var t:Number = segment.thickness;
var st:Number = segment.startThickness;
var et:Number = segment.endThickness;
var sa:Number = segment.startAlpha;
var ea:Number = segment.endAlpha;

var subSet:SubSet = _subSets[segment.subSetIndex];
var vertices:Vector.<Number> = subSet.vertices;
Expand All @@ -259,47 +264,47 @@
vertices[index++] = endX;
vertices[index++] = endY;
vertices[index++] = endZ;
vertices[index++] = t;
vertices[index++] = st;
vertices[index++] = startR;
vertices[index++] = startG;
vertices[index++] = startB;
vertices[index++] = 1;
vertices[index++] = sa;

vertices[index++] = endX;
vertices[index++] = endY;
vertices[index++] = endZ;
vertices[index++] = startX;
vertices[index++] = startY;
vertices[index++] = startZ;
vertices[index++] = -t;
vertices[index++] = -et;
vertices[index++] = endR;
vertices[index++] = endG;
vertices[index++] = endB;
vertices[index++] = 1;
vertices[index++] = ea;

vertices[index++] = startX;
vertices[index++] = startY;
vertices[index++] = startZ;
vertices[index++] = endX;
vertices[index++] = endY;
vertices[index++] = endZ;
vertices[index++] = -t;
vertices[index++] = -st;
vertices[index++] = startR;
vertices[index++] = startG;
vertices[index++] = startB;
vertices[index++] = 1;
vertices[index++] = sa;

vertices[index++] = endX;
vertices[index++] = endY;
vertices[index++] = endZ;
vertices[index++] = startX;
vertices[index++] = startY;
vertices[index++] = startZ;
vertices[index++] = t;
vertices[index++] = et;
vertices[index++] = endR;
vertices[index++] = endG;
vertices[index++] = endB;
vertices[index++] = 1;
vertices[index++] = ea;

subSet.vertexBufferDirty = true;

Expand Down
8 changes: 8 additions & 0 deletions src/away3d/materials/SegmentMaterial.as
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package away3d.materials
{
import away3d.arcane;
import away3d.materials.passes.SegmentPass;
import flash.display.BlendMode;

use namespace arcane;

Expand All @@ -26,6 +27,13 @@ package away3d.materials
bothSides = true;
addPass(_screenPass = new SegmentPass(thickness));
_screenPass.material = this;
blendMode = BlendMode.NORMAL;
}

override public function set blendMode(value:String):void
{
super.blendMode = value;
_screenPass.setBlendMode(value);
}
}
}
70 changes: 61 additions & 9 deletions src/away3d/primitives/data/Segment.as
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ package away3d.primitives.data
public class Segment
{
arcane var _segmentsBase:SegmentSet;
arcane var _thickness:Number;
arcane var _startThickness:Number;
arcane var _endThickness:Number;
arcane var _start:Vector3D;
arcane var _end:Vector3D;
arcane var _startR:Number;
Expand All @@ -24,13 +25,16 @@ package away3d.primitives.data
private var _subSetIndex:int = -1;
private var _startColor:uint;
private var _endColor:uint;
private var _startAlpha:Number;
private var _endAlpha:Number;

public function Segment(start:Vector3D, end:Vector3D, anchor:Vector3D, colorStart:uint = 0x333333, colorEnd:uint = 0x333333, thickness:Number = 1):void
{
// TODO: not yet used: for CurveSegment support
anchor = null;

_thickness = thickness*.5;
_startThickness = thickness*.5;
_endThickness = thickness*.5;
// TODO: add support for curve using anchor v1
// Prefer removing v1 from this, and make Curve a separate class extending Segment? (- David)
_start = start;
Expand All @@ -39,20 +43,24 @@ package away3d.primitives.data
endColor = colorEnd;
}

public function updateSegment(start:Vector3D, end:Vector3D, anchor:Vector3D, colorStart:uint = 0x333333, colorEnd:uint = 0x333333, thickness:Number = 1):void
public function updateSegment(start:Vector3D, end:Vector3D, anchor:Vector3D, colorStart:uint = 0x333333, colorEnd:uint = 0x333333, startThickness:Number = 1, endThickness:Number = NaN, alphaStart:Number = 1, alphaEnd:Number = 1):void
{
// TODO: not yet used: for CurveSegment support
anchor = null;
_start = start;
_end = end;

_startAlpha = alphaStart;
_endAlpha = alphaEnd;

if (_startColor != colorStart)
startColor = colorStart;

if (_endColor != colorEnd)
endColor = colorEnd;

_thickness = thickness*.5;
_startThickness = startThickness*.5;
_endThickness = (isNaN(endThickness) ? startThickness : endThickness) *.5;
update();
}

Expand Down Expand Up @@ -84,17 +92,37 @@ package away3d.primitives.data
update();
}

/**
* Defines the ending vertex.
*/
public function get thickness():Number
{
return _thickness*2;
return _startThickness*2;
}

public function set thickness(value:Number):void
{
_thickness = value*.5;
_startThickness = value*.5;
_endThickness = value*.5;
update();
}

public function get startThickness():Number
{
return _startThickness*2;
}

public function set startThickness(value:Number):void
{
_startThickness = value*.5;
update();
}

public function get endThickness():Number
{
return _endThickness*2;
}

public function set endThickness(value:Number):void
{
_endThickness = value*.5;
update();
}

Expand Down Expand Up @@ -136,6 +164,30 @@ package away3d.primitives.data
update();
}

public function get startAlpha():Number
{
return _startAlpha;
}

public function set startAlpha(value:Number):void
{
_startAlpha = value;

update();
}

public function get endAlpha():Number
{
return _endAlpha;
}

public function set endAlpha(value:Number):void
{
_endAlpha = value;

update();
}

public function dispose():void
{
_start = null;
Expand Down