TextureAttributes/Voronoi
This commit is contained in:
parent
3d008531fd
commit
1c98676862
|
|
@ -21,6 +21,9 @@ namespace Rokojori
|
||||||
[Export]
|
[Export]
|
||||||
public TextureAttributes.Channel channel = TextureAttributes.Channel.Red;
|
public TextureAttributes.Channel channel = TextureAttributes.Channel.Red;
|
||||||
|
|
||||||
|
[Export]
|
||||||
|
public TextureAttributes.OperatorType operatorType = TextureAttributes.OperatorType.Set;
|
||||||
|
|
||||||
protected override void _OnTrigger()
|
protected override void _OnTrigger()
|
||||||
{
|
{
|
||||||
var ta = textureAttributes;
|
var ta = textureAttributes;
|
||||||
|
|
@ -37,7 +40,7 @@ namespace Rokojori
|
||||||
}
|
}
|
||||||
|
|
||||||
this.LogInfo( "Index", index, "Value:", value, "Channel:", channel );
|
this.LogInfo( "Index", index, "Value:", value, "Channel:", channel );
|
||||||
ta.SetChannel( index, value, channel );
|
ta.SetChannel( index, value, channel, operatorType );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -26,6 +26,11 @@ namespace Rokojori
|
||||||
Red, Green, Blue, Alpha
|
Red, Green, Blue, Alpha
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum OperatorType
|
||||||
|
{
|
||||||
|
Set, Add, Subtract, Multiply
|
||||||
|
}
|
||||||
|
|
||||||
[Export]
|
[Export]
|
||||||
public Size sizeType =Size._64;
|
public Size sizeType =Size._64;
|
||||||
|
|
||||||
|
|
@ -132,7 +137,33 @@ namespace Rokojori
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetChannel( int index, float value, Channel channel )
|
float ApplyOperator( float leftValue, float rightValue, OperatorType operatorType )
|
||||||
|
{
|
||||||
|
if ( OperatorType.Set == operatorType )
|
||||||
|
{
|
||||||
|
return rightValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( OperatorType.Add == operatorType )
|
||||||
|
{
|
||||||
|
return leftValue + rightValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( OperatorType.Subtract == operatorType )
|
||||||
|
{
|
||||||
|
return leftValue - rightValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( OperatorType.Multiply == operatorType )
|
||||||
|
{
|
||||||
|
return leftValue * rightValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return leftValue;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetChannel( int index, float value, Channel channel, OperatorType operatorType = OperatorType.Set )
|
||||||
{
|
{
|
||||||
Update(
|
Update(
|
||||||
( Image i ) =>
|
( Image i ) =>
|
||||||
|
|
@ -142,19 +173,19 @@ namespace Rokojori
|
||||||
|
|
||||||
if ( channel == Channel.Red )
|
if ( channel == Channel.Red )
|
||||||
{
|
{
|
||||||
currentValue.R = value;
|
currentValue.R = ApplyOperator( currentValue.R, value, operatorType );
|
||||||
}
|
}
|
||||||
else if ( channel == Channel.Green )
|
else if ( channel == Channel.Green )
|
||||||
{
|
{
|
||||||
currentValue.G = value;
|
currentValue.G = ApplyOperator( currentValue.G, value, operatorType );
|
||||||
}
|
}
|
||||||
else if ( channel == Channel.Blue )
|
else if ( channel == Channel.Blue )
|
||||||
{
|
{
|
||||||
currentValue.B = value;
|
currentValue.B = ApplyOperator( currentValue.B, value, operatorType );
|
||||||
}
|
}
|
||||||
else if ( channel == Channel.Alpha )
|
else if ( channel == Channel.Alpha )
|
||||||
{
|
{
|
||||||
currentValue.A = value;
|
currentValue.A = ApplyOperator( currentValue.A, value, operatorType );
|
||||||
}
|
}
|
||||||
|
|
||||||
i.SetPixelv( uv, currentValue );
|
i.SetPixelv( uv, currentValue );
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,9 @@ namespace Rokojori
|
||||||
{
|
{
|
||||||
return boundaries.Map( b => _voronoi2D.boundaryPoints[ b ] );
|
return boundaries.Map( b => _voronoi2D.boundaryPoints[ b ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vector2 center => _voronoi2D.cellPoints[ index ];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue