Merge branch 'main' of community.rokojori.com:Rokojori/rj-action-library

This commit is contained in:
Josef 2025-04-19 09:59:49 +02:00
commit 97324647ce
78 changed files with 1623 additions and 874 deletions

View File

@ -40,7 +40,7 @@ vec4 dilate(sampler2D a_tex, sampler2D tex, vec2 coords, vec2 texel_size, int di
return sample; return sample;
} }
void fragment() { void fragment()
{
COLOR = dilate(u_alpha_tex, TEXTURE, UV, TEXTURE_PIXEL_SIZE, u_distance, 0.95); COLOR = dilate(u_alpha_tex, TEXTURE, UV, TEXTURE_PIXEL_SIZE, u_distance, 0.95);
//COLOR.a = 1.0;
} }

View File

@ -10,6 +10,19 @@ namespace Rokojori
{ {
GizmoDrawerPlugin gizmoDrawerPlugin = new GizmoDrawerPlugin(); GizmoDrawerPlugin gizmoDrawerPlugin = new GizmoDrawerPlugin();
static readonly string RokojoriRootAutoLoad = "RokojoriRootAutoLoad";
static readonly string RokojoriRootAutoLoadPath = "res://addons/rokojori_action_library/Runtime/Godot/Root.cs";
public override void _EnablePlugin()
{
AddAutoloadSingleton( RokojoriRootAutoLoad, RokojoriRootAutoLoadPath );
}
public override void _DisablePlugin()
{
RemoveAutoloadSingleton( RokojoriRootAutoLoad );
}
public override void _EnterTree() public override void _EnterTree()
{ {
AddNode3DGizmoPlugin( gizmoDrawerPlugin ); AddNode3DGizmoPlugin( gizmoDrawerPlugin );

View File

@ -19,6 +19,7 @@ namespace Rokojori
</summary> </summary>
*/ */
[Tool]
[GlobalClass, Icon("res://addons/rokojori_action_library/Icons/ActionList.svg") ] [GlobalClass, Icon("res://addons/rokojori_action_library/Icons/ActionList.svg") ]
public partial class ActionList : Action public partial class ActionList : Action
{ {

View File

@ -0,0 +1,100 @@
using System.Collections.Generic;
using Godot;
using Rokojori;
namespace Rokojori
{
[Tool]
[GlobalClass, Icon("res://addons/rokojori_action_library/Icons/OnEvent.svg") ]
public partial class OnCollision:Node
{
[Export]
public Area3D area;
[Export]
public Selector selector;
[Export]
public Action onEntered;
[Export]
public Action onInside;
[Export]
public Action onExit;
Dictionary<Node,System.Action> _inside = new Dictionary<Node,System.Action>();
public override void _Ready()
{
if ( area == null )
{
return;
}
area.AreaEntered += TriggerOnEnter;
area.BodyEntered += TriggerOnEnter;
area.AreaExited += TriggerOnExited;
area.BodyExited += TriggerOnExited;
}
void TriggerOnEnter( Node n )
{
if ( ! Selector.IsSelecting( selector, n ) )
{
return;
}
Action.Trigger( onEntered );
if ( onInside == null )
{
return;
}
var tm = Unique<TimeLineManager>.Get();
if ( tm == null )
{
return;
}
var callback = ()=>{ Action.Trigger( onInside ); };
_inside[ n ] = callback;
tm.AddProcessCallback( callback );
}
void TriggerOnExited( Node n )
{
if ( ! Selector.IsSelecting( selector, n ) )
{
return;
}
Action.Trigger( onExit );
if ( ! _inside.ContainsKey( n ) )
{
return;
}
var tm = Unique<TimeLineManager>.Get();
if ( tm == null )
{
return;
}
var callback = _inside[ n ];
tm.RemoveProcessCallback( callback );
_inside.Remove( n );
}
}
}

View File

@ -0,0 +1 @@
uid://c8gcunaffcaww

View File

@ -0,0 +1,17 @@
using Godot;
namespace Rokojori
{
[GlobalClass]
public partial class PlayParticles:Action
{
[Export]
public GpuParticles3D particles3D;
protected override void _OnTrigger()
{
particles3D.Restart();
}
}
}

View File

@ -0,0 +1 @@
uid://dnstanbmrqthf

View File

@ -0,0 +1,17 @@
using Godot;
namespace Rokojori
{
[GlobalClass]
public partial class PlaySound:Action
{
[Export]
public AudioStreamPlayer player;
protected override void _OnTrigger()
{
player.Play();
}
}
}

View File

@ -0,0 +1 @@
uid://ddgf2mfdmqywc

View File

@ -226,6 +226,34 @@ namespace Rokojori
return CreateChildIn<T>( parent, name ); return CreateChildIn<T>( parent, name );
} }
public static T CreateChildLocal3D<T>( this Node parent, Vector3 position, Quaternion? rotation, string name = null ) where T:Node3D,new()
{
var c = CreateChildIn<T>( parent, name );
c.Position = position;
if ( rotation != null )
{
Math3D.SetLocalQuaternion( c, (Quaternion)rotation );
}
return c;
}
public static T CreateChildGlobal3D<T>( this Node parent, Vector3 position, Quaternion? rotation, string name = null ) where T:Node3D,new()
{
var c = CreateChildIn<T>( parent, name );
c.GlobalPosition = position;
if ( rotation != null )
{
Math3D.SetGlobalQuaternion( c, (Quaternion)rotation );
}
return c;
}
public static Node CreateChildWithType( this Node parent, Type type, string name = null ) public static Node CreateChildWithType( this Node parent, Type type, string name = null )
{ {
return CreateChildInWithType( parent, type, name ); return CreateChildInWithType( parent, type, name );
@ -372,6 +400,7 @@ namespace Rokojori
} }
} }
public static T GetDirectChild<T>( Node parent ) where T:Node public static T GetDirectChild<T>( Node parent ) where T:Node
{ {
if ( parent == null ) if ( parent == null )

View File

@ -21,6 +21,12 @@ namespace Rokojori
return new Aabb( box.min, box.size ); return new Aabb( box.min, box.size );
} }
public void Translate( Vector3 translation )
{
min += translation;
max += translation;
}
public static Box3 FromPositionAndScale( Vector3 position, Vector3 scale ) public static Box3 FromPositionAndScale( Vector3 position, Vector3 scale )
{ {
var max = scale * 0.5f; var max = scale * 0.5f;
@ -40,6 +46,11 @@ namespace Rokojori
public Vector3 size => max - min; public Vector3 size => max - min;
public void IncludePoint( Vector3 p )
{
min = min.Min( p );
max = max.Max( p );
}
public Box2 AsXZBox2() public Box2 AsXZBox2()
{ {

View File

@ -242,16 +242,26 @@ namespace Rokojori
return quaternion; return quaternion;
} }
public static Vector3 MinPosition( Node3D a, Node3D b ) public static Vector3 MinGlobalPosition( Node3D a, Node3D b )
{ {
return a.GlobalPosition.Min( b.GlobalPosition ); return a.GlobalPosition.Min( b.GlobalPosition );
} }
public static Vector3 MaxPosition( Node3D a, Node3D b ) public static Vector3 MaxGlobalPosition( Node3D a, Node3D b )
{ {
return a.GlobalPosition.Max( b.GlobalPosition ); return a.GlobalPosition.Max( b.GlobalPosition );
} }
public static Vector3 MinLocalPosition( Node3D a, Node3D b )
{
return a.Position.Min( b.Position );
}
public static Vector3 MaxLocalPosition( Node3D a, Node3D b )
{
return a.Position.Max( b.Position );
}
public static Vector3 SnapRounded( Vector3 v, Vector3 snapping ) public static Vector3 SnapRounded( Vector3 v, Vector3 snapping )
{ {
v.X = MathX.SnapRounded( v.X, snapping.X ); v.X = MathX.SnapRounded( v.X, snapping.X );
@ -443,6 +453,13 @@ namespace Rokojori
node.Scale = localScale; node.Scale = localScale;
} }
public static void SetLocalQuaternion( this Node3D node, Quaternion quaternion )
{
var localScale = node.Scale;
node.Basis = new Basis( quaternion );
node.Scale = localScale;
}
public static void SetGlobalRotationTo( Node3D node, Quaternion quaternion ) public static void SetGlobalRotationTo( Node3D node, Quaternion quaternion )
{ {
var forward = quaternion * Vector3.Forward; var forward = quaternion * Vector3.Forward;

View File

@ -24,20 +24,6 @@ namespace Rokojori
[Export] [Export]
public bool updateAlways; public bool updateAlways;
[ExportGroup( "Blades")]
[Export( PropertyHint.Range, "0,100")]
public int blades = 20;
[Export( PropertyHint.Range, "0,100")]
public int bladesX = 0;
[Export( PropertyHint.Range, "0,100")]
public int bladesZ = 0;
[Export]
public int X_numBlades;
[ExportGroup( "Patch")] [ExportGroup( "Patch")]
[Export] [Export]
public float patchSize = 2; public float patchSize = 2;
@ -58,7 +44,24 @@ namespace Rokojori
public float centerPatchComputationHeightTreshold = 0.1f; public float centerPatchComputationHeightTreshold = 0.1f;
[ExportGroup( "Blade Triangles")] [ExportGroup( "Blades")]
[Export( PropertyHint.Range, "0,100")]
public int blades = 20;
[Export( PropertyHint.Range, "0,100")]
public int bladesX = 0;
[Export( PropertyHint.Range, "0,100")]
public int bladesZ = 0;
[Export]
public int X_numBlades;
[ExportGroup( "Triangles")]
[Export( PropertyHint.Range, "1,256")] [Export( PropertyHint.Range, "1,256")]
public int bladeSegments = 3; public int bladeSegments = 3;
@ -75,7 +78,7 @@ namespace Rokojori
[Export] [Export]
public Curve bladeSegmentMapping = MathX.Curve( 0, 1 ); public Curve bladeSegmentMapping = MathX.Curve( 0, 1 );
[ExportGroup( "Blade Segmentation")] [ExportGroup( "Segmentation")]
[Export] [Export]
public int uvSegmentColumns = 1; public int uvSegmentColumns = 1;
@ -95,7 +98,7 @@ namespace Rokojori
public float uvSegmentMaxRange = 0.3f; public float uvSegmentMaxRange = 0.3f;
[ExportGroup( "Blade Shape")] [ExportGroup( "Shape")]
[Export] [Export]
public Curve bladeHeight = MathX.Curve( 0.4f ); public Curve bladeHeight = MathX.Curve( 0.4f );
@ -109,19 +112,14 @@ namespace Rokojori
[Export] [Export]
public Curve bladeWidth2 = null; public Curve bladeWidth2 = null;
[ExportGroup( "Curve")]
[Export] [Export]
public Curve bladeBending = MathX.Curve( 0f ); public Curve bladeBending = MathX.Curve( 0f );
[Export] [Export]
public Curve bladeBending2 = null; public Curve bladeBending2 = null;
[Export]
public Curve bladeArching = MathX.Curve( 0f );
[Export]
public Curve bladeArching2 = null;
[Export] [Export]
public Curve bladeTwisting = null; public Curve bladeTwisting = null;
@ -135,7 +133,7 @@ namespace Rokojori
public Curve rolling2 = null; public Curve rolling2 = null;
[ExportGroup( "Blade Offset")] [ExportGroup( "Offset")]
[Export] [Export]
public Curve positionJitter = MathX.Curve( 0.05f ); public Curve positionJitter = MathX.Curve( 0.05f );
@ -148,7 +146,7 @@ namespace Rokojori
[ExportGroup( "Blade Scale")] [ExportGroup( "Scale")]
[Export] [Export]
public Curve bladeScale = MathX.Curve( 1f ); public Curve bladeScale = MathX.Curve( 1f );
@ -178,7 +176,7 @@ namespace Rokojori
public Curve scaleZForY = null; public Curve scaleZForY = null;
[ExportGroup( "Blade Rotation")] [ExportGroup( "Rotation")]
[Export] [Export]
public Curve yawRotation = MathX.Curve( 0f, 1f ); public Curve yawRotation = MathX.Curve( 0f, 1f );
@ -186,8 +184,24 @@ namespace Rokojori
[Export] [Export]
public Curve randomRotation = MathX.Curve( 0f, 20f ); public Curve randomRotation = MathX.Curve( 0f, 20f );
[ExportGroup( "Noise")]
[Export]
public Curve vertexTurbulenceAmount = MathX.Curve( 0f, 0f );
[ExportGroup( "Blade Normals")] [Export]
public Curve vertexTurbulenceScale = MathX.Curve( 1f, 1f );
[Export]
public Curve vertexTurbulenceScaleX = MathX.Curve( 1f, 1f );
[Export]
public Curve vertexTurbulenceScaleY = MathX.Curve( 1f, 1f );
[Export]
public Curve vertexTurbulenceScaleZ = MathX.Curve( 1f, 1f );
[ExportGroup( "Normals")]
[Export] [Export]
public Curve normalBlending = MathX.Curve( 0.5f ); public Curve normalBlending = MathX.Curve( 0.5f );
@ -199,7 +213,7 @@ namespace Rokojori
[ExportGroup( "Blade Filter")] [ExportGroup( "Filter")]
[Export (PropertyHint.Range, "0,1")] [Export (PropertyHint.Range, "0,1")]
public float filterTreshold = 1; public float filterTreshold = 1;
@ -412,6 +426,29 @@ namespace Rokojori
mg.CenterMesh( true, false, true, box ); mg.CenterMesh( true, false, true, box );
} }
if ( vertexTurbulenceAmount != null )
{
var turbulenceAmount = random.Sample( vertexTurbulenceAmount );
var turbulenceScale = Vector3.One * ( vertexTurbulenceScale == null ? 1 : random.Sample( vertexTurbulenceScale ) );
if ( vertexTurbulenceScaleX != null )
{
turbulenceScale.X *= random.Sample( vertexTurbulenceScaleX );
}
if ( vertexTurbulenceScaleY != null )
{
turbulenceScale.Y *= random.Sample( vertexTurbulenceScaleY );
}
if ( vertexTurbulenceScaleZ != null )
{
turbulenceScale.Z *= random.Sample( vertexTurbulenceScaleX );
}
mg.Turbulence( turbulenceAmount, turbulenceScale, Vector3.Zero );
}
if ( xRemapper != null ) if ( xRemapper != null )
{ {
mg.RemapX( xRemapper ); mg.RemapX( xRemapper );
@ -442,6 +479,8 @@ namespace Rokojori
mg.ScaleZForY( scaleZForY ); mg.ScaleZForY( scaleZForY );
} }
X_numTriangles = mg.indices.Count / 3; X_numTriangles = mg.indices.Count / 3;

View File

@ -11,174 +11,97 @@ namespace Rokojori
[GlobalClass] [GlobalClass]
public partial class Baker:Node public partial class Baker:Node
{ {
public enum CameraDistanceDetectionType
{
Automatic_Distance_Detection,
Custom_Distance
}
public enum CameraFOVMode [ExportToolButton( "Update")]
{ public Callable BakeButton => Callable.From( () => Bake() );
Keep_Fov,
Compute_Fov_With_Distance,
Custom_Fov
}
public enum MeshMode
{
World_Scale,
Custom_Scale
}
[Export]
public bool update = false;
[Export] [Export]
public bool updateAlways = false; public bool updateAlways = false;
[ExportGroup( "View") ]
[Export]
public BakingViewSettings viewSettings = new BakingViewSettings();
[Export] [Export]
public Viewport viewport; public Viewport viewport;
[Export]
public Node3D target;
[Export] [Export]
public Camera3D camera; public Camera3D camera;
[Export] [ExportGroup( "Target")]
public float originalFOV = 75;
[Export] [Export]
public bool assignFOV = false; public Node3D target;
[Export] [Export]
public float placingDistance = 500; public Vector3 targetPivot;
[Export] [Export]
public float computedFOV = 75; public bool autoTargetPivot = true;
[Export]
public bool useCustomFOV = false;
[Export] [ExportGroup( "Output")]
public float customFOV = 75;
[Export]
public bool useCustomDistance = false;
[Export]
public float customDistance = 50;
[Export]
public float outputScale = 1;
[Export] [Export]
public Node3D outputTexture; public Node3D outputTexture;
[Export]
public float outputScale = 1;
[Export] [Export]
public float outputTextureSize = 1; public float outputTextureSize = 1;
public enum RotationMode
public static Baker Create( Node parent, Node3D target, Vector2I size, string name )
{ {
Yaw_Pitch, var bakingView = parent.CreateChild<SubViewport>( "Viewport " + name );
Quaternion bakingView.TransparentBg = true;
bakingView.Size = size;
var bakingCamera = bakingView.CreateChild<Camera3D>( "Camera View " + name );
var baker = bakingView.CreateChild<Baker>( "Baker " + name );
baker.camera = bakingCamera;
baker.target = target;
baker.viewport = bakingView;
return baker;
} }
[ExportGroup("Rotation")]
[Export]
public RotationMode rotationMode = RotationMode.Yaw_Pitch;
[Export( PropertyHint.Range, "-180,180")]
public float yaw = 0;
[Export( PropertyHint.Range, "-180,180")]
public float pitch = 0;
[Export]
public Quaternion rotationQuaternion;
public Quaternion bakingRotation => RotationMode.Yaw_Pitch == rotationMode ?
Math3D.YawPitchRotation( yaw, pitch ) :
rotationQuaternion;
[Export]
public float zoom = 1;
[Export]
public float distance = 1;
public override void _Process( double delta ) public override void _Process( double delta )
{ {
if ( ! ( update || updateAlways ) ) if ( ! updateAlways )
{ {
return; return;
} }
update = false;
Bake(); Bake();
} }
void Bake() public void Bake()
{ {
if ( viewport == null || target == null || camera == null ) if ( viewport == null || target == null || camera == null )
{ {
return; return;
} }
var box = target.GetWorldBounds(); if ( autoTargetPivot )
if ( box == null )
{ {
RJLog.Log( "No target" ); Box3 box = target.GetWorldBounds();
return; targetPivot = new Vector3( 0, -box.center.Y, 0 );
} }
var sphere = Sphere.ContainingBox( box ); viewSettings.ApplySettings( camera, target, targetPivot );
camera.Fov = originalFOV;
var billboardFOV = camera.Fov; var outputScale = Cameras.ComputeCameraFittingScale( camera.Fov, viewSettings._XX_ComputedDistance );
if ( assignFOV )
{
computedFOV = Cameras.ComputeFOVForBillboard( originalFOV, sphere.radius, placingDistance );
billboardFOV = computedFOV;
camera.Fov = billboardFOV;
}
if ( useCustomFOV )
{
billboardFOV = customFOV;
camera.Fov = billboardFOV;
}
var newDistance = useCustomDistance ? customDistance : Cameras.ComputeCameraFrameFittingDistance( billboardFOV, sphere.radius / zoom );
if ( newDistance != distance )
{
distance = newDistance;
// RJLog.Log( "New Distance:", box, sphere, distance );
}
var cameraRotation = bakingRotation;
var offset = ( Vector3.Back * distance ) * cameraRotation ;
camera.GlobalPosition = target.GlobalPosition + offset;
camera.SetGlobalQuaternion( cameraRotation.Inverse() );
// RJLog.Log( "Set Rotation", cameraRotation, ">>", camera.GetGlobalQuaternion() );
outputScale = Cameras.ComputeCameraFittingScale( camera.Fov, distance );
if ( outputTexture != null ) if ( outputTexture != null )
{ {
outputTexture.Scale = Vector3.One * outputScale; outputTexture.Scale = Vector3.One * outputScale;
outputTexture.GlobalPosition = target.GlobalPosition - targetPivot;
} }
} }

View File

@ -1,14 +1,14 @@
[gd_resource type="Resource" script_class="SubMaterialTransfer" load_steps=16 format=3 uid="uid://crxw8r6q5uhpe"] [gd_resource type="Resource" script_class="SubMaterialTransfer" load_steps=16 format=3 uid="uid://crxw8r6q5uhpe"]
[ext_resource type="Resource" uid="uid://cwbo0avyyq0t" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Color/Albedo Color.tres" id="1_vhp84"] [ext_resource type="Resource" uid="uid://cwbo0avyyq0t" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Color/Albedo Color.tres" id="1_vhp84"]
[ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/Transfers/ColorPropertyTransfer.cs" id="2_awr2w"] [ext_resource type="Script" uid="uid://c4kkc55ia5udl" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/Transfers/ColorPropertyTransfer.cs" id="2_awr2w"]
[ext_resource type="Resource" uid="uid://bja8pltfjyt3x" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Float/Alpha Scissor Threshold.tres" id="3_baip0"] [ext_resource type="Resource" uid="uid://bja8pltfjyt3x" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Float/Alpha Scissor Threshold.tres" id="3_baip0"]
[ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/Transfers/FloatPropertyTransfer.cs" id="4_r0n2g"] [ext_resource type="Script" uid="uid://dbjd6oaknq055" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/Transfers/FloatPropertyTransfer.cs" id="4_r0n2g"]
[ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/SubMaterialTransfer.cs" id="5_iuqjk"] [ext_resource type="Script" uid="uid://cwp8to3eakdrm" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/SubMaterialTransfer.cs" id="5_iuqjk"]
[ext_resource type="Resource" uid="uid://dldbju3x0x2ow" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Texture2D/Albedo Texture.tres" id="6_tcnva"] [ext_resource type="Resource" uid="uid://dldbju3x0x2ow" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Texture2D/Albedo Texture.tres" id="6_tcnva"]
[ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/Transfers/Texture2DPropertyTransfer.cs" id="7_pf381"] [ext_resource type="Script" uid="uid://c55j0ppclm0k" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/Transfers/Texture2DPropertyTransfer.cs" id="7_pf381"]
[ext_resource type="Resource" uid="uid://cn7nxc0qw7pan" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Vector3/UV1 Offset.tres" id="8_00usm"] [ext_resource type="Resource" uid="uid://cn7nxc0qw7pan" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Vector3/UV1 Offset.tres" id="8_00usm"]
[ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/Transfers/Vector3PropertyTransfer.cs" id="9_sn3qs"] [ext_resource type="Script" uid="uid://sm7n01wb77f1" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/Transfers/Vector3PropertyTransfer.cs" id="9_sn3qs"]
[ext_resource type="Resource" uid="uid://douianw6mx4p5" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Vector3/UV1 Scale.tres" id="10_5fqi2"] [ext_resource type="Resource" uid="uid://douianw6mx4p5" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Vector3/UV1 Scale.tres" id="10_5fqi2"]
[sub_resource type="Resource" id="Resource_7u5wc"] [sub_resource type="Resource" id="Resource_7u5wc"]

View File

@ -1,16 +1,16 @@
[gd_resource type="Resource" script_class="SubMaterialTransfer" load_steps=20 format=3 uid="uid://dgyihly620ymm"] [gd_resource type="Resource" script_class="SubMaterialTransfer" load_steps=20 format=3 uid="uid://dgyihly620ymm"]
[ext_resource type="Resource" uid="uid://cwbo0avyyq0t" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Color/Albedo Color.tres" id="1_8s4ko"] [ext_resource type="Resource" uid="uid://cwbo0avyyq0t" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Color/Albedo Color.tres" id="1_8s4ko"]
[ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/Transfers/ColorPropertyTransfer.cs" id="2_edgft"] [ext_resource type="Script" uid="uid://c4kkc55ia5udl" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/Transfers/ColorPropertyTransfer.cs" id="2_edgft"]
[ext_resource type="Resource" uid="uid://bja8pltfjyt3x" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Float/Alpha Scissor Threshold.tres" id="3_8a5am"] [ext_resource type="Resource" uid="uid://bja8pltfjyt3x" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Float/Alpha Scissor Threshold.tres" id="3_8a5am"]
[ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/Transfers/FloatPropertyTransfer.cs" id="4_wnydu"] [ext_resource type="Script" uid="uid://dbjd6oaknq055" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/Transfers/FloatPropertyTransfer.cs" id="4_wnydu"]
[ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/SubMaterialTransfer.cs" id="5_atmxl"] [ext_resource type="Script" uid="uid://cwp8to3eakdrm" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/SubMaterialTransfer.cs" id="5_atmxl"]
[ext_resource type="Resource" uid="uid://c6actnjj8i8o5" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Float/Normal Scale.tres" id="5_iyqth"] [ext_resource type="Resource" uid="uid://c6actnjj8i8o5" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Float/Normal Scale.tres" id="5_iyqth"]
[ext_resource type="Resource" uid="uid://dldbju3x0x2ow" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Texture2D/Albedo Texture.tres" id="6_l0r8p"] [ext_resource type="Resource" uid="uid://dldbju3x0x2ow" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Texture2D/Albedo Texture.tres" id="6_l0r8p"]
[ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/Transfers/Texture2DPropertyTransfer.cs" id="7_l54r2"] [ext_resource type="Script" uid="uid://c55j0ppclm0k" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/Transfers/Texture2DPropertyTransfer.cs" id="7_l54r2"]
[ext_resource type="Resource" uid="uid://bmt10lgwm8ckx" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Texture2D/Normal Texture.tres" id="9_fmy5n"] [ext_resource type="Resource" uid="uid://bmt10lgwm8ckx" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Texture2D/Normal Texture.tres" id="9_fmy5n"]
[ext_resource type="Resource" uid="uid://cn7nxc0qw7pan" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Vector3/UV1 Offset.tres" id="10_dw87i"] [ext_resource type="Resource" uid="uid://cn7nxc0qw7pan" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Vector3/UV1 Offset.tres" id="10_dw87i"]
[ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/Transfers/Vector3PropertyTransfer.cs" id="11_mpsiy"] [ext_resource type="Script" uid="uid://sm7n01wb77f1" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/Transfers/Vector3PropertyTransfer.cs" id="11_mpsiy"]
[ext_resource type="Resource" uid="uid://douianw6mx4p5" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Vector3/UV1 Scale.tres" id="12_xnkjm"] [ext_resource type="Resource" uid="uid://douianw6mx4p5" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Vector3/UV1 Scale.tres" id="12_xnkjm"]
[sub_resource type="Resource" id="Resource_7u5wc"] [sub_resource type="Resource" id="Resource_7u5wc"]

View File

@ -1,22 +1,22 @@
[gd_resource type="Resource" script_class="SubMaterialTransfer" load_steps=36 format=3 uid="uid://kwk45f3p6ic4"] [gd_resource type="Resource" script_class="SubMaterialTransfer" load_steps=36 format=3 uid="uid://kwk45f3p6ic4"]
[ext_resource type="Resource" uid="uid://cwbo0avyyq0t" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Color/Albedo Color.tres" id="1_b7tdx"] [ext_resource type="Resource" uid="uid://cwbo0avyyq0t" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Color/Albedo Color.tres" id="1_b7tdx"]
[ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/Transfers/ColorPropertyTransfer.cs" id="2_vwrue"] [ext_resource type="Script" uid="uid://c4kkc55ia5udl" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/Transfers/ColorPropertyTransfer.cs" id="2_vwrue"]
[ext_resource type="Resource" uid="uid://txmti1ghef1" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/TextureChannels/AO Texture Channel.tres" id="3_rkwtk"] [ext_resource type="Resource" uid="uid://txmti1ghef1" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/TextureChannels/AO Texture Channel.tres" id="3_rkwtk"]
[ext_resource type="Resource" uid="uid://bja8pltfjyt3x" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Float/Alpha Scissor Threshold.tres" id="3_u377f"] [ext_resource type="Resource" uid="uid://bja8pltfjyt3x" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Float/Alpha Scissor Threshold.tres" id="3_u377f"]
[ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/Transfers/FloatPropertyTransfer.cs" id="4_ed7jn"] [ext_resource type="Script" uid="uid://dbjd6oaknq055" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/Transfers/FloatPropertyTransfer.cs" id="4_ed7jn"]
[ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/Transfers/TextureChannelToVector4Transfer.cs" id="4_ubpsj"] [ext_resource type="Script" uid="uid://hged4kw2qsv8" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/Transfers/TextureChannelToVector4Transfer.cs" id="4_ubpsj"]
[ext_resource type="Resource" uid="uid://dy4yrg7cbx84g" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Float/Metallic.tres" id="5_hkpx0"] [ext_resource type="Resource" uid="uid://dy4yrg7cbx84g" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Float/Metallic.tres" id="5_hkpx0"]
[ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/SubMaterialTransfer.cs" id="6_7dw2g"] [ext_resource type="Script" uid="uid://cwp8to3eakdrm" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/SubMaterialTransfer.cs" id="6_7dw2g"]
[ext_resource type="Resource" uid="uid://dn4k668h72myc" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Float/Roughness.tres" id="6_8likw"] [ext_resource type="Resource" uid="uid://dn4k668h72myc" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Float/Roughness.tres" id="6_8likw"]
[ext_resource type="Resource" uid="uid://xoj2836knmix" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/TextureChannels/Metallic Texture Channel.tres" id="6_v4lhi"] [ext_resource type="Resource" uid="uid://xoj2836knmix" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/TextureChannels/Metallic Texture Channel.tres" id="6_v4lhi"]
[ext_resource type="Resource" uid="uid://dldbju3x0x2ow" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Texture2D/Albedo Texture.tres" id="7_yqc2y"] [ext_resource type="Resource" uid="uid://dldbju3x0x2ow" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Texture2D/Albedo Texture.tres" id="7_yqc2y"]
[ext_resource type="Resource" uid="uid://d2x1ijwsv2urr" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/TextureChannels/Roughness Texture Channel.tres" id="8_gljck"] [ext_resource type="Resource" uid="uid://d2x1ijwsv2urr" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/TextureChannels/Roughness Texture Channel.tres" id="8_gljck"]
[ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/Transfers/Texture2DPropertyTransfer.cs" id="8_iwxjk"] [ext_resource type="Script" uid="uid://c55j0ppclm0k" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/Transfers/Texture2DPropertyTransfer.cs" id="8_iwxjk"]
[ext_resource type="Resource" uid="uid://cow6rei03x5bs" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Texture2D/AO Texture.tres" id="10_8mfy8"] [ext_resource type="Resource" uid="uid://cow6rei03x5bs" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Texture2D/AO Texture.tres" id="10_8mfy8"]
[ext_resource type="Resource" uid="uid://cn7nxc0qw7pan" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Vector3/UV1 Offset.tres" id="10_y3nsy"] [ext_resource type="Resource" uid="uid://cn7nxc0qw7pan" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Vector3/UV1 Offset.tres" id="10_y3nsy"]
[ext_resource type="Resource" uid="uid://csiwpeupf761o" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Texture2D/Metallic Texture.tres" id="11_i36mp"] [ext_resource type="Resource" uid="uid://csiwpeupf761o" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Texture2D/Metallic Texture.tres" id="11_i36mp"]
[ext_resource type="Script" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/Transfers/Vector3PropertyTransfer.cs" id="11_on6ta"] [ext_resource type="Script" uid="uid://sm7n01wb77f1" path="res://addons/rokojori_action_library/Runtime/Shading/Materials/Transfers/Vector3PropertyTransfer.cs" id="11_on6ta"]
[ext_resource type="Resource" uid="uid://douianw6mx4p5" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Vector3/UV1 Scale.tres" id="12_a173h"] [ext_resource type="Resource" uid="uid://douianw6mx4p5" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Vector3/UV1 Scale.tres" id="12_a173h"]
[ext_resource type="Resource" uid="uid://bdjlvcpc13hl6" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Texture2D/Roughness Texture.tres" id="12_u6pwu"] [ext_resource type="Resource" uid="uid://bdjlvcpc13hl6" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Texture2D/Roughness Texture.tres" id="12_u6pwu"]
[ext_resource type="Resource" uid="uid://bprgfki4joe6x" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Vector4/AO Texture Channel.tres" id="16_56ntu"] [ext_resource type="Resource" uid="uid://bprgfki4joe6x" path="res://addons/rokojori_action_library/Runtime/Shading/Properties/Property Library/Vector4/AO Texture Channel.tres" id="16_56ntu"]

View File

@ -1,20 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using Godot;
using System;
using System.Threading.Tasks;
namespace Rokojori
{
public abstract class MultiBakeModeImplementation
{
public MultiBaker multiBaker;
public abstract MultiBaker.BakeMode GetBakeMode();
public abstract int GetNumViews();
public abstract void CreateBakes();
public abstract void AssignMaterial( BakingMaterialMode mode, Texture2D texture );
public abstract void CreateMaterial( bool preview );
}
}

View File

@ -1,142 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using Godot;
using System;
using System.Threading.Tasks;
namespace Rokojori
{
public class MultiBakeModeCrossBraces:MultiBakeModeBillboardBase
{
public override MultiBaker.BakeMode GetBakeMode()
{
return MultiBaker.BakeMode.Cross_Braces;
}
public override int GetNumViews()
{
var views = multiBaker.crossAngles * 2;
if ( multiBaker.crossBottom )
{
views ++;
}
if ( multiBaker.crossTop )
{
views ++;
}
return views;
}
public override void CreateBakes()
{
var fov = multiBaker.GetCameraFOV();
var distance = multiBaker.GetCameraDistance();
var outputScale = multiBaker.GetOutputScale();
var _bakers = multiBaker.bakers;
var mb = multiBaker;
_bakers.ForEach(
b =>
{
b.useCustomFOV = true;
b.customFOV = fov;
b.useCustomDistance = true;
b.customDistance = distance;
b.rotationMode = Baker.RotationMode.Yaw_Pitch;
}
);
var index = 0;
var mg = new MeshGeometry();
var numTextures = GetNumViews();
var textureAlignment = TextureMerger.ComputeTextureAlignment( numTextures );
if ( mb.crossTop )
{
_bakers[ index ].yaw = 0 + mb.crossAngleOffset;
_bakers[ index ].pitch = 90f;
var uv = TextureMerger.GetUVRectangle( textureAlignment, index, true );
var q = new MeshGeometry();
q.AddQuad( _bakers[ index ].bakingRotation, outputScale, uv.min, uv.max );
mg.Add( q );
index ++;
}
if ( mb.crossBottom )
{
_bakers[ index ].yaw = 0 + mb.crossAngleOffset;
_bakers[ index ].pitch = -90f;
var uv = TextureMerger.GetUVRectangle( textureAlignment, index, true );
var q = new MeshGeometry();
q.AddQuad( _bakers[ index ].bakingRotation, outputScale, uv.min, uv.max );
mg.Add( q );
index ++;
}
for ( int i = 0; i < mb.crossAngles; i++ )
{
for ( int side = 0; side < 2; side ++ )
{
var angle = ( 180f * i ) / (float) mb.crossAngles;
_bakers[ index ].yaw = side == 0 ? angle : ( MathX.Repeat( angle + 180f, 360f ) );
_bakers[ index ].yaw += mb.crossAngleOffset;
_bakers[ index ].pitch = 0;
var uv = TextureMerger.GetUVRectangle( textureAlignment, index, true );
var q = new MeshGeometry();
q.AddQuad( _bakers[ index ].bakingRotation, outputScale, uv.min, uv.max );
if ( mb.crossBraces > 1 )
{
var normal = Vector3.Forward * _bakers[ index ].bakingRotation;
var startOffset = normal * mb.crossSpreadDistance * 0.5f;
var endOffset = -startOffset;
for ( int brace = 0; brace < mb.crossBraces; brace ++ )
{
var bq = q.Clone();
var lerpAmount = (float)brace / (float)( mb.crossBraces - 1 );
var offset = startOffset.Lerp( endOffset, lerpAmount );
bq.ApplyTranslation( offset );
mg.Add( bq );
}
}
else
{
mg.Add( q );
}
index ++;
}
}
mb.X_outputMesh.Mesh = mg.GenerateMesh();
}
}
}

View File

@ -1,155 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using Godot;
using System;
using System.Threading.Tasks;
namespace Rokojori
{
public class MultiBakeModeCylinder:MultiBakeModeBillboardBase
{
public override MultiBaker.BakeMode GetBakeMode()
{
return MultiBaker.BakeMode.Cylinder;
}
public override int GetNumViews()
{
var cylinderViews = multiBaker.cylinderSides;
if ( multiBaker.cylinderBottom )
{
cylinderViews ++;
}
if ( multiBaker.cylinderTop )
{
cylinderViews ++;
}
return cylinderViews;
}
public override void CreateBakes()
{
var fov = multiBaker.GetCameraFOV();
var distance = multiBaker.GetCameraDistance();
var outputScale = multiBaker.GetOutputScale();
var _bakers = multiBaker.bakers;
var mb = multiBaker;
_bakers.ForEach(
b =>
{
b.useCustomFOV = true;
b.customFOV = fov;
b.useCustomDistance = true;
b.customDistance = distance;
b.rotationMode = Baker.RotationMode.Yaw_Pitch;
}
);
var index = 0;
var mg = new MeshGeometry();
var numTextures = GetNumViews();
var textureAlignment = TextureMerger.ComputeTextureAlignment( numTextures );
if ( mb.cylinderTop )
{
_bakers[ index ].yaw = 0;
_bakers[ index ].pitch = 90f;
var uv = TextureMerger.GetUVRectangle( textureAlignment, index, true );
var q = new MeshGeometry();
q.AddQuad( _bakers[ index ].bakingRotation, outputScale, uv.min, uv.max );
if ( mb.cylinderTopOffset != 0 )
{
var topOffset = Vector3.Up * mb.cylinderTopOffset * outputScale * 0.5f;
q.ApplyTranslation( topOffset, -4 );
}
mg.Add( q );
if ( mb.createBackFacesForTop )
{
q.FlipNormalDirection();
mg.Add( q );
}
index ++;
}
if ( mb.cylinderBottom )
{
_bakers[ index ].yaw = 0;
_bakers[ index ].pitch = -90f;
var uv = TextureMerger.GetUVRectangle( textureAlignment, index, true );
var q = new MeshGeometry();
q.AddQuad( _bakers[ index ].bakingRotation, outputScale, uv.min, uv.max );
if ( mb.cylinderBottomOffset != 0 )
{
var bottomOffset = Vector3.Down * mb.cylinderBottomOffset * outputScale * 0.5f;
q.ApplyTranslation( bottomOffset, -4 );
}
mg.Add( q );
if ( mb.createBackFacesForBottom )
{
q.FlipNormalDirection();
mg.Add( q );
}
index ++;
}
for ( int i = 0; i < mb.cylinderSides; i++ )
{
var angle = ( 360f * i ) / (float) mb.cylinderSides;
_bakers[ index ].yaw = angle;
_bakers[ index ].pitch = 0;
var uv = TextureMerger.GetUVRectangle( textureAlignment, index, true );
var q = new MeshGeometry();
q.AddQuad( _bakers[ index ].bakingRotation, outputScale, uv.min, uv.max );
if ( mb.cylinderSideOffset != 0 )
{
var sideOffset = Vector3.Forward *_bakers[ index ].bakingRotation * mb.cylinderSideOffset * outputScale * -0.5f;
q.ApplyTranslation( sideOffset, -4 );
}
mg.Add( q );
if ( mb.createBackFacesForSides )
{
q.FlipNormalDirection();
mg.Add( q );
}
index++;
}
mb.X_outputMesh.Mesh = mg.GenerateMesh();
}
}
}

View File

@ -1,42 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using Godot;
using System;
using System.Threading.Tasks;
namespace Rokojori
{
public class MultiBakeModeSpherical:MultiBakeModeImplementation
{
public readonly string sphericalShader = "res://addons/rokojori_action_library/External/Imposter/materials/shaders/ImpostorShader.gdshader";
public override MultiBaker.BakeMode GetBakeMode()
{
return MultiBaker.BakeMode.Spherical;
}
public override int GetNumViews()
{
var views = multiBaker.sphericalSides * multiBaker.sphericalRows;
return views;
}
public override void CreateMaterial( bool preview )
{
}
public override void AssignMaterial( BakingMaterialMode mode, Texture2D texture )
{
}
public override void CreateBakes()
{
}
}
}

View File

@ -0,0 +1,150 @@
using System.Collections;
using System.Collections.Generic;
using Godot;
using System;
using System.Threading.Tasks;
namespace Rokojori
{
[Tool][GlobalClass]
public partial class CrossBraces_Baker:_XX_MultiBakeModeBillboardBase
{
[Export]
public int crossAngles = 2;
[Export]
public int crossBraces = 3;
[Export]
public float crossSpreadDistance = 1;
[Export]
public float crossAngleOffset = 0;
[Export]
public bool crossTop = false;
[Export]
public bool crossBottom = false;
public override int GetNumViews()
{
var views = crossAngles * 2;
if ( crossBottom )
{
views ++;
}
if ( crossTop )
{
views ++;
}
return views;
}
public override void CreateBakers()
{
var fov = multiBaker.GetCameraFOV();
var distance = multiBaker.GetCameraDistance();
var outputScale = multiBaker.GetOutputScale();
RJLog.Log( "outputScale", outputScale );
var _bakers = multiBaker.bakers;
var mb = multiBaker;
_bakers.ForEach(
bk =>
{
var vs = bk.viewSettings;
vs.fovDistance = Manual_BakingFDSettings.Create( fov, distance );
vs.rotationMode = BakingViewSettings.RotationMode.Yaw_Pitch;
}
);
var index = 0;
var mg = new MeshGeometry();
var numTextures = GetNumViews();
var textureAlignment = TextureMerger.ComputeTextureAlignment( numTextures );
if ( crossTop )
{
_bakers[ index ].viewSettings.yaw = 0 + crossAngleOffset;
_bakers[ index ].viewSettings.pitch = 90f;
var uv = TextureMerger.GetUVRectangle( textureAlignment, index, true );
var q = new MeshGeometry();
q.AddQuad( _bakers[ index ].viewSettings.bakingRotation, outputScale, uv.min, uv.max );
mg.Add( q );
index ++;
}
if ( crossBottom )
{
_bakers[ index ].viewSettings.yaw = 0 + crossAngleOffset;
_bakers[ index ].viewSettings.pitch = -90f;
var uv = TextureMerger.GetUVRectangle( textureAlignment, index, true );
var q = new MeshGeometry();
q.AddQuad( _bakers[ index ].viewSettings.bakingRotation, outputScale, uv.min, uv.max );
mg.Add( q );
index ++;
}
for ( int i = 0; i < crossAngles; i++ )
{
for ( int side = 0; side < 2; side ++ )
{
var angle = ( 180f * i ) / (float) crossAngles;
_bakers[ index ].viewSettings.yaw = side == 0 ? angle : ( MathX.Repeat( angle + 180f, 360f ) );
_bakers[ index ].viewSettings.yaw += crossAngleOffset;
_bakers[ index ].viewSettings.pitch = 0;
var uv = TextureMerger.GetUVRectangle( textureAlignment, index, true );
var q = new MeshGeometry();
q.AddQuad( _bakers[ index ].viewSettings.bakingRotation, outputScale, uv.min, uv.max );
if ( crossBraces > 1 )
{
var normal = Vector3.Forward * _bakers[ index ].viewSettings.bakingRotation;
var startOffset = normal * crossSpreadDistance * 0.5f;
var endOffset = -startOffset;
for ( int brace = 0; brace < crossBraces; brace ++ )
{
var bq = q.Clone();
var lerpAmount = (float)brace / (float)( crossBraces - 1 );
var offset = startOffset.Lerp( endOffset, lerpAmount );
bq.ApplyTranslation( offset );
mg.Add( bq );
}
}
else
{
mg.Add( q );
}
index ++;
}
}
mb.X_outputMesh.Mesh = mg.GenerateMesh();
}
}
}

View File

@ -0,0 +1,167 @@
using System.Collections;
using System.Collections.Generic;
using Godot;
using System;
using System.Threading.Tasks;
namespace Rokojori
{
[Tool][GlobalClass]
public partial class Cylinder_Baker:_XX_MultiBakeModeBillboardBase
{
[Export]
public int cylinderSides = 4;
[Export]
public bool createBackFacesForSides = false;
[Export]
public bool cylinderTop = false;
[Export]
public bool createBackFacesForTop = false;
[Export]
public bool cylinderBottom = false;
[Export]
public bool createBackFacesForBottom = false;
[Export( PropertyHint.Range, "-1,1" )]
public float cylinderSideOffset = 0;
[Export( PropertyHint.Range, "-1,1" )]
public float cylinderTopOffset = 0f;
[Export( PropertyHint.Range, "-1,1" )]
public float cylinderBottomOffset = 0f;
public override int GetNumViews()
{
var cylinderViews = cylinderSides;
if ( cylinderBottom )
{
cylinderViews ++;
}
if ( cylinderTop )
{
cylinderViews ++;
}
return cylinderViews;
}
public override void CreateBakers()
{
var fov = multiBaker.GetCameraFOV();
var distance = multiBaker.GetCameraDistance();
var outputScale = multiBaker.GetOutputScale();
var _bakers = multiBaker.bakers;
var mb = multiBaker;
_bakers.ForEach(
bk =>
{
var vs = bk.viewSettings;
vs.fovDistance = Manual_BakingFDSettings.Create( fov, distance );
vs.rotationMode = BakingViewSettings.RotationMode.Yaw_Pitch;
}
);
var index = 0;
var mg = new MeshGeometry();
var numTextures = GetNumViews();
var textureAlignment = TextureMerger.ComputeTextureAlignment( numTextures );
if ( cylinderTop )
{
_bakers[ index ].viewSettings.yaw = 0;
_bakers[ index ].viewSettings.pitch = 90f;
var uv = TextureMerger.GetUVRectangle( textureAlignment, index, true );
var q = new MeshGeometry();
q.AddQuad( _bakers[ index ].viewSettings.bakingRotation, outputScale, uv.min, uv.max );
if ( cylinderTopOffset != 0 )
{
var topOffset = Vector3.Up * cylinderTopOffset * outputScale * 0.5f;
q.ApplyTranslation( topOffset, -4 );
}
mg.Add( q );
if ( createBackFacesForTop )
{
q.FlipNormalDirection();
mg.Add( q );
}
index ++;
}
if ( cylinderBottom )
{
_bakers[ index ].viewSettings.yaw = 0;
_bakers[ index ].viewSettings.pitch = -90f;
var uv = TextureMerger.GetUVRectangle( textureAlignment, index, true );
var q = new MeshGeometry();
q.AddQuad( _bakers[ index ].viewSettings.bakingRotation, outputScale, uv.min, uv.max );
if ( cylinderBottomOffset != 0 )
{
var bottomOffset = Vector3.Down * cylinderBottomOffset * outputScale * 0.5f;
q.ApplyTranslation( bottomOffset, -4 );
}
mg.Add( q );
if ( createBackFacesForBottom )
{
q.FlipNormalDirection();
mg.Add( q );
}
index ++;
}
for ( int i = 0; i < cylinderSides; i++ )
{
var angle = ( 360f * i ) / (float) cylinderSides;
_bakers[ index ].viewSettings.yaw = angle;
_bakers[ index ].viewSettings.pitch = 0;
var uv = TextureMerger.GetUVRectangle( textureAlignment, index, true );
var q = new MeshGeometry();
q.AddQuad( _bakers[ index ].viewSettings.bakingRotation, outputScale, uv.min, uv.max );
if ( cylinderSideOffset != 0 )
{
var sideOffset = Vector3.Forward *_bakers[ index ].viewSettings.bakingRotation * cylinderSideOffset * outputScale * -0.5f;
q.ApplyTranslation( sideOffset, -4 );
}
mg.Add( q );
if ( createBackFacesForSides )
{
q.FlipNormalDirection();
mg.Add( q );
}
index++;
}
mb.X_outputMesh.Mesh = mg.GenerateMesh();
}
}
}

View File

@ -11,20 +11,14 @@ namespace Rokojori
[GlobalClass] [GlobalClass]
public partial class MultiBaker:Node public partial class MultiBaker:Node
{ {
[Export] [ExportToolButton( "Bake")]
public bool initialize; public Callable BakeButton => Callable.From( () => StartBaking() );
public bool bake;
public bool saveTexture;
[ExportGroup("Preview")]
[Export] [Export]
public bool preview_UpdateAlways = true; public bool cleanUpAfterBaking = true;
[Export] [Export]
public bool preview_DilateTextures = true; public _XX_MultiBakeMode bakeMode;
public enum MaterialMode public enum MaterialMode
{ {
@ -36,6 +30,8 @@ namespace Rokojori
[Export] [Export]
public MaterialMode materialMode; public MaterialMode materialMode;
[Export]
public int dilationRadius = 64;
[ExportGroup("Material/Full Seperated")] [ExportGroup("Material/Full Seperated")]
[Export] [Export]
public bool mmfs_Normals = true; public bool mmfs_Normals = true;
@ -45,89 +41,44 @@ namespace Rokojori
public bool mmfs_ORM = true; public bool mmfs_ORM = true;
public enum BakeMode
{
Cylinder,
Cross_Braces,
Octahedral,
Spherical,
Cloud
}
[ExportGroup("BakeMode")]
[Export]
public BakeMode bakeMode;
[ExportGroup("BakeMode/Cylinder")]
[Export]
public int cylinderSides = 4;
[Export]
public bool createBackFacesForSides = false;
[Export]
public bool cylinderTop = false;
[Export]
public bool createBackFacesForTop = false;
[Export]
public bool cylinderBottom = false;
[Export]
public bool createBackFacesForBottom = false;
[Export( PropertyHint.Range, "-1,1" )]
public float cylinderSideOffset = 0;
[Export( PropertyHint.Range, "-1,1" )]
public float cylinderTopOffset = 0f;
[Export( PropertyHint.Range, "-1,1" )]
public float cylinderBottomOffset = 0f;
[ExportGroup("BakeMode/Cross Braces")]
[Export]
public int crossAngles = 2;
[Export]
public int crossBraces = 3;
[Export]
public float crossSpreadDistance = 1;
[Export]
public float crossAngleOffset = 0;
[Export]
public bool crossTop = false;
[Export]
public bool crossBottom = false;
[ExportGroup("BakeMode/Octahedral")]
[Export]
public int octahedralSides = 4;
[Export]
public bool octahedralFullSphere = false;
[ExportGroup("BakeMode/Spherical")]
[Export]
public int sphericalSides = 4;
[Export]
public int sphericalRows = 3;
[Export]
public float minPitch = -30;
[Export]
public float maxPitch = 30;
[ExportGroup( "Object")] [ExportGroup( "Object")]
[Export] [Export]
public Node3D sourceTarget; public Node3D target;
[Export] [Export]
public bool autoCenter = false; public bool autoTargetPivot = false;
[Export] [Export]
public Vector3 sourceOffset; public Vector3 targetPivot;
[ExportGroup( "Camera")] [ExportGroup( "Camera")]
[Export]
public BakingViewSettings viewSettings;
public float cameraZoom
{
get
{
if ( viewSettings.fovDistance is AutoDistance_BakingFDSettings ad )
{
return ad.zoom;
}
if ( viewSettings.fovDistance is AutoDistance_BakingFDSettings afd )
{
return afd.zoom;
}
return 1;
}
}
/*
[Export] [Export]
public Baker.CameraDistanceDetectionType distanceDetectionType = Baker.CameraDistanceDetectionType.Automatic_Distance_Detection; public Baker.CameraDistanceDetectionType distanceDetectionType = Baker.CameraDistanceDetectionType.Automatic_Distance_Detection;
@ -145,7 +96,7 @@ namespace Rokojori
public float fovPlacingDistance = 200; public float fovPlacingDistance = 200;
[Export] [Export]
public float customFOV = 75; public float customFOV = 75;
*/
[ExportGroup( "Output")] [ExportGroup( "Output")]
@ -180,9 +131,6 @@ namespace Rokojori
[Export] [Export]
public WorldEnvironment X_worldEnvironment; public WorldEnvironment X_worldEnvironment;
[Export]
public DilateTexture X_dilateTexture;
[Export] [Export]
public MeshInstance3D X_outputMesh; public MeshInstance3D X_outputMesh;
@ -211,62 +159,82 @@ namespace Rokojori
public Texture2D X_bakedTextureDepth; public Texture2D X_bakedTextureDepth;
[Export]
public bool X_baking = false;
public void StartBaking()
bool _initialized = false;
bool _baking = false;
SerializedGodotObject _cached;
public override void _Ready()
{ {
Initialize(); Initialize();
}
public override void _Process( double delta )
{
X_texturePreview.Visible = showOutputTexture;
if ( _baking )
{
return;
}
if ( initialize || ! _initialized )
{
initialize = false;
Initialize();
}
var current = SerializedGodotObject.Create( this );
var changed = _cached != null && ! _cached.Equals( current );
_cached = current;
if ( bake || changed && preview_UpdateAlways )
{
bake = false;
Bake(); Bake();
} }
public void Initialize()
{
this.LogInfo( "Initializing" );
Nodes.RemoveAndDeleteChildren( this );
_bakers = null;
X_bakingViewport = this.CreateChild<SubViewport>( "Multi Baker Viewport" );
X_bakingViewport.Size = (Vector2I) outputTextureSize;
X_bakingViewport.OwnWorld3D = true;
X_bakingViewport.TransparentBg = true;
X_worldEnvironment = X_bakingViewport.CreateChild<WorldEnvironment>( "Multi Baker Environment" );
X_worldEnvironment.Environment = new Godot.Environment();
X_worldEnvironment.Environment.AmbientLightSource = Godot.Environment.AmbientSource.Color;
X_worldEnvironment.Environment.AmbientLightColor = HSLColor.white;
X_bakingTargetContainer = X_bakingViewport.CreateChild<Node3D>( "Target Container" );
X_views = X_bakingViewport.CreateChild<Node>( "Views" );
X_textureMerger = this.CreateChild<TextureMerger>( "Texture Merger" );
X_textureMerger.multiBaker = this;
X_textureMerger.dilationRadius = dilationRadius;
X_textureMerger.Initialize();
X_outputMesh = this.CreateChild<MeshInstance3D>( "Output Mesh" );
X_texturePreview = this.CreateChild<MeshInstance3D>( "Texture Preview" );
X_texturePreview.Mesh = new QuadMesh();
X_texturePreview.Scale = Vector3.One * 100;
var pm = new StandardMaterial3D();
pm.Transparency = BaseMaterial3D.TransparencyEnum.AlphaScissor;
pm.ResourceLocalToScene = true;
var vt = new ViewportTexture();
vt.ViewportPath = X_textureMerger.X_textureMergerViewport.GetPath();
pm.AlbedoTexture = vt;
X_setBakingMaterials = this.CreateChild<SetBakingMaterials>( "Set Baking Materials" );
Materials.Set( X_texturePreview, pm );
} }
public async Task Bake() public async Task Bake()
{ {
_baking = true; if ( X_baking )
{
return;
}
X_baking = true;
try try
{ {
bakeMode.multiBaker = this;
this.LogInfo( "Started baking" ); this.LogInfo( "Started baking" );
Nodes.RemoveAndDeleteChildren( X_bakingTargetContainer ); Nodes.RemoveAndDeleteChildren( X_bakingTargetContainer );
sourceTarget.DeepCopyTo( X_bakingTargetContainer ); target.DeepCopyTo( X_bakingTargetContainer );
if ( _bakers == null || _bakers.Count != GetNumViews() ) if ( _bakers == null || _bakers.Count != GetNumViews() )
{ {
@ -274,20 +242,20 @@ namespace Rokojori
await this.RequestNextFrame(); await this.RequestNextFrame();
} }
SetupViews(); SetupViews();
this.LogInfo( "Views set up" ); this.LogInfo( "Views set up" );
await this.RequestNextFrame(); await this.RequestNextFrame();
X_setBakingMaterials.SetTarget( X_bakingTargetContainer );
X_setBakingMaterials.SetTarget( X_bakingTargetContainer );
var bakingMaterialModes = new List<BakingMaterialMode>(); var bakingMaterialModes = new List<BakingMaterialMode>();
var preview_QuickMaterial = MaterialMode.Simple_Prebaked == materialMode; var preview_QuickMaterial = MaterialMode.Simple_Prebaked == materialMode;
GetBakeModeImplementation().CreateMaterial( preview_QuickMaterial ); bakeMode.CreateMaterial( preview_QuickMaterial );
if ( preview_QuickMaterial ) if ( preview_QuickMaterial )
{ {
@ -314,47 +282,37 @@ namespace Rokojori
} }
this.LogInfo( "Prepared baking modes" ); this.LogInfo( "Prepared baking modes" );
X_textureMerger.textureSize = outputTextureSize; X_textureMerger.textureSize = outputTextureSize;
X_textureMerger.Initialize(); X_textureMerger.Initialize();
X_textureMerger.CreateLayout(); X_textureMerger.CreateLayout();
this.LogInfo( "Prepared texture merger" ); this.LogInfo( "Prepared texture merger" );
// var fovDistance = viewSettings.fovDistance.ComputeFOVDistance(
var objectDistance = GetCameraDistance(); var objectDistance = GetCameraDistance();
this.LogInfo( "Set Camera Distance", objectDistance );
for ( int i = 0; i < bakingMaterialModes.Count; i++ ) for ( int i = 0; i < bakingMaterialModes.Count; i++ )
{ {
this.LogInfo( "Baking mode:", bakingMaterialModes[ i ] ); this.LogInfo( "Baking mode:", bakingMaterialModes[ i ] );
X_setBakingMaterials.mode = bakingMaterialModes[ i ]; X_setBakingMaterials.mode = bakingMaterialModes[ i ];
X_setBakingMaterials.ApplyBakingMaterials( objectDistance, _targetBoundingSphere.radius ); X_setBakingMaterials.ApplyBakingMaterials( objectDistance, _targetBoundingSphere.radius );
this.LogInfo( "Materials changed:", bakingMaterialModes[ i ] ); this.LogInfo( "Materials changed:", bakingMaterialModes[ i ] );
_bakers.ForEach( b => b.Bake() );
await this.RequestNextFrame(); await this.RequestNextFrame();
Texture2D texture = X_textureMerger.X_textureMergerViewport.GetTexture(); Texture2D texture = X_textureMerger.X_textureMergerViewport.GetTexture();
this.LogInfo( "Texture created:", bakingMaterialModes[ i ] ); this.LogInfo( "Texture created:", bakingMaterialModes[ i ] );
if ( preview_DilateTextures )
{
this.LogInfo( "Dilating:", bakingMaterialModes[ i ] );
texture = await CreateDilatedTexture();
this.LogInfo( "Dilating done:", bakingMaterialModes[ i ] );
}
else
{
texture = Textures.Copy( texture ); texture = Textures.Copy( texture );
await this.RequestNextFrame(); await this.RequestNextFrame();
await this.RequestNextFrame(); await this.RequestNextFrame();
}
this.LogInfo( "Assigning Texture", bakingMaterialModes[ i ] ); this.LogInfo( "Assigning Texture", bakingMaterialModes[ i ] );
GetBakeModeImplementation().AssignMaterial( bakingMaterialModes[ i ], texture ); bakeMode.AssignMaterial( bakingMaterialModes[ i ], texture );
this.LogInfo( "Baking done:", bakingMaterialModes[ i ] ); this.LogInfo( "Baking done:", bakingMaterialModes[ i ] );
@ -364,7 +322,17 @@ namespace Rokojori
await this.RequestNextFrame(); await this.RequestNextFrame();
// this.LogInfo( "Baking done" ); X_outputMesh.GlobalPosition = target.GlobalPosition - targetPivot;
X_outputMesh.Scale = Vector3.One * cameraZoom;
if ( cleanUpAfterBaking )
{
this.LogInfo( "Cleaning Up" );
CleanUp();
}
this.LogInfo( "All Baking done" );
} }
catch ( System.Exception e ) catch ( System.Exception e )
@ -373,63 +341,16 @@ namespace Rokojori
this.LogError( e ); this.LogError( e );
} }
_baking = false; X_baking = false;
return; return;
} }
public async Task<Texture2D> CreateDilatedTexture()
{
var viewports = GetAllViewports();
var textures = Lists.Map( viewports, v => v.GetTexture() as Texture2D );
var dilatedTextures = new List<Texture2D>();
var index = 0;
foreach ( var t in textures )
{
index ++;
var dilatedTexture = await X_dilateTexture.Create( t );
dilatedTextures.Add( dilatedTexture );
}
X_textureMerger.sourceTextures = dilatedTextures.ToArray();
X_textureMerger.sourceMode = TextureMerger.SourceMode.Textures;
X_textureMerger.Initialize();
await this.RequestNextFrame();
X_textureMerger.CreateLayout();
await this.RequestNextFrame();
var finalTexture = await X_dilateTexture.Create( X_textureMerger.X_textureMergerViewport.GetTexture() );
return finalTexture;
}
public List<SubViewport> GetAllViewports() public List<SubViewport> GetAllViewports()
{ {
return Nodes.AllIn<SubViewport>( X_views, null, false ); return Nodes.AllIn<SubViewport>( X_views, null, false );
} }
List<MultiBakeModeImplementation> _bakeModeImplementations = new List<MultiBakeModeImplementation>()
{
new MultiBakeModeCylinder(),
new MultiBakeModeCrossBraces(),
new MultiBakeModeOctahedral()
};
public MultiBakeModeImplementation GetBakeModeImplementation()
{
var bm = _bakeModeImplementations.Find( bm => bm.GetBakeMode() == bakeMode );
bm.multiBaker = this;
return bm;
}
public void CacheTexture( BakingMaterialMode mode, Texture2D texture ) public void CacheTexture( BakingMaterialMode mode, Texture2D texture )
{ {
if ( BakingMaterialMode.Albedo == mode ) if ( BakingMaterialMode.Albedo == mode )
@ -451,60 +372,47 @@ namespace Rokojori
} }
public void Initialize() public void CleanUp()
{ {
this.LogInfo( "Initializing" ); var mesh = X_outputMesh;
mesh.Reparent( GetParent(), true );
X_bakingViewport = null;
X_bakingTargetContainer = null;
X_views = null;
X_worldEnvironment = null;
X_outputMesh = null;
X_textureMerger = null;
X_setBakingMaterials = null;
X_texturePreview = null;
X_depthMapper = null;
X_bakedTextureAlbedo = null;
X_bakedTextureNormal = null;
X_bakedTextureORM = null;
X_bakedTextureDepth = null;
Nodes.RemoveAndDeleteChildren( this ); Nodes.RemoveAndDeleteChildren( this );
_bakers = null; mesh.Reparent( this, true );
X_bakingViewport = this.CreateChild<SubViewport>( "Multi Baker Viewport" );
X_bakingViewport.Size = (Vector2I) outputTextureSize;
X_bakingViewport.OwnWorld3D = true;
X_bakingViewport.TransparentBg = true;
X_worldEnvironment = X_bakingViewport.CreateChild<WorldEnvironment>( "Multi Baker Environment" );
X_worldEnvironment.Environment = new Godot.Environment();
X_worldEnvironment.Environment.AmbientLightSource = Godot.Environment.AmbientSource.Color;
X_worldEnvironment.Environment.AmbientLightColor = HSLColor.white;
X_bakingTargetContainer = X_bakingViewport.CreateChild<Node3D>( "Target Container" );
X_views = X_bakingViewport.CreateChild<Node>( "Views" );
X_dilateTexture = this.CreateChild<DilateTexture>( "Dilate Texture" );
X_textureMerger = this.CreateChild<TextureMerger>( "Texture Merger" );
X_textureMerger.multiBaker = this;
X_textureMerger.Initialize();
X_outputMesh = this.CreateChild<MeshInstance3D>( "Output Mesh" );
X_texturePreview = this.CreateChild<MeshInstance3D>( "Texture Preview" );
X_texturePreview.Mesh = new QuadMesh();
X_texturePreview.Scale = Vector3.One * 100;
var pm = new StandardMaterial3D();
pm.Transparency = BaseMaterial3D.TransparencyEnum.AlphaScissor;
pm.ResourceLocalToScene = true;
var vt = new ViewportTexture();
vt.ViewportPath = X_textureMerger.X_textureMergerViewport.GetPath();
pm.AlbedoTexture = vt;
X_setBakingMaterials = this.CreateChild<SetBakingMaterials>( "Set Baking Materials" );
Materials.Set( X_texturePreview, pm );
_initialized = true;
} }
public int GetNumViews() public int GetNumViews()
{ {
return GetBakeModeImplementation().GetNumViews(); return bakeMode.GetNumViews();
} }
List<Baker> _bakers; List<Baker> _bakers;
@ -537,7 +445,7 @@ namespace Rokojori
baker.viewport = bakingView; baker.viewport = bakingView;
baker.update = true;
_bakers.Add( baker ); _bakers.Add( baker );
} }
@ -558,6 +466,8 @@ namespace Rokojori
} }
_targetBoundingSphere = null; _targetBoundingSphere = null;
_targetBoundingBox = null;
ComputeBoundingSphere(); ComputeBoundingSphere();
if ( _targetBoundingSphere == null ) if ( _targetBoundingSphere == null )
@ -566,22 +476,16 @@ namespace Rokojori
return; return;
} }
var bmi = GetBakeModeImplementation(); ComputeCameraViewSettings();
bakeMode.CreateBakers();
if ( bmi == null )
{
return;
}
bmi.CreateBakes();
/*if ( X_bakedTextureAlbedo != null )
{
bmi.AssignMaterial( BakingMaterialMode.Albedo, X_bakedTextureAlbedo );
}*/
} }
Sphere _targetBoundingSphere; Sphere _targetBoundingSphere;
Box3 _targetBoundingBox;
Sphere targetBoundingSphere Sphere targetBoundingSphere
{ {
@ -617,45 +521,62 @@ namespace Rokojori
firstChild.Visible = true; firstChild.Visible = true;
} }
var worldBounds = X_bakingTargetContainer.GetWorldBounds(); _targetBoundingBox = X_bakingTargetContainer.GetWorldBounds();
if ( autoTargetPivot )
{
Box3 box = target.GetWorldBounds();
targetPivot = new Vector3( 0, -box.center.Y, 0 );
}
_targetBoundingSphere = Sphere.ContainingBox( worldBounds ); _targetBoundingSphere = Sphere.ContainingBox( _targetBoundingBox );
}
float _cameraFOV = 0;
float _cameraDistance = 0;
float _outputScale = 1;
void ComputeCameraViewSettings()
{
var fovDistance = viewSettings.fovDistance;
var size = targetBoundingSphere.radius;
var computeScale = false;
if ( fovDistance is AutoDistance_BakingFDSettings ad )
{
size = ad.sizeEstimation == _XX_BakingFDSettings.SizeEstimationType.Bounding_Sphere ?
targetBoundingSphere.radius : ( _targetBoundingBox.size.Y / 2f );
computeScale = true;
}
if ( fovDistance is AutoFOVDistance_BakingFDSettings afd )
{
size = afd.sizeEstimation == _XX_BakingFDSettings.SizeEstimationType.Bounding_Sphere ?
targetBoundingSphere.radius : ( _targetBoundingBox.size.Y / 2f );
computeScale = true;
}
var fd = fovDistance.ComputeFOVDistance( size / 2f );
_cameraFOV = fd.X;
_cameraDistance = fd.Y;
_outputScale = computeScale ? Cameras.ComputeCameraFittingScale( _cameraFOV, _cameraDistance ) : 1;
} }
public float GetCameraFOV() public float GetCameraFOV()
{ {
if ( Baker.CameraFOVMode.Custom_Fov == fovMode ) return _cameraFOV;
{
return customFOV;
}
if ( Baker.CameraFOVMode.Keep_Fov == fovMode )
{
return originalFOV;
}
return Cameras.ComputeFOVForBillboard( originalFOV, targetBoundingSphere.radius, fovPlacingDistance );
} }
public float GetCameraDistance() public float GetCameraDistance()
{ {
if ( Baker.CameraDistanceDetectionType.Custom_Distance == distanceDetectionType ) return _cameraDistance;
{
return customDistance;
}
var fov = GetCameraFOV();
return Cameras.ComputeCameraFrameFittingDistance( fov, targetBoundingSphere.radius / cameraZoom );
} }
public float GetOutputScale() public float GetOutputScale()
{ {
var fov = GetCameraFOV(); return _outputScale;
var distance = GetCameraDistance();
return Cameras.ComputeCameraFittingScale( fov, distance );
} }
} }
} }

View File

@ -0,0 +1,14 @@
using System.Collections;
using System.Collections.Generic;
using Godot;
using System;
using System.Threading.Tasks;
namespace Rokojori
{
public class MultiBakerCameraTools
{
}
}

View File

@ -0,0 +1 @@
uid://bwqywi630pq3h

View File

@ -7,18 +7,22 @@ using System.Threading.Tasks;
namespace Rokojori namespace Rokojori
{ {
public class MultiBakeModeOctahedral:MultiBakeModeImplementation [Tool]
[GlobalClass]
public partial class Octahedral_Baker:_XX_MultiBakeMode
{ {
public readonly string octahedralShader = "res://addons/rokojori_action_library/External/Imposter/materials/shaders/ImpostorShader.gdshader"; public static readonly string octahedralShader = "res://addons/rokojori_action_library/External/Imposter/materials/shaders/ImpostorShader.gdshader";
[Export]
public int octahedralSides = 4;
[Export]
public bool octahedralFullSphere = false;
public override MultiBaker.BakeMode GetBakeMode()
{
return MultiBaker.BakeMode.Octahedral;
}
public override int GetNumViews() public override int GetNumViews()
{ {
var views = multiBaker.octahedralSides * multiBaker.octahedralSides; var views = octahedralSides * octahedralSides;
return views; return views;
} }
@ -29,8 +33,8 @@ namespace Rokojori
var material = new ShaderMaterial(); var material = new ShaderMaterial();
material.Shader = ResourceLoader.Load( octahedralShader ) as Shader; material.Shader = ResourceLoader.Load( octahedralShader ) as Shader;
material.SetShaderParameter( "isFullSphere", mb.octahedralFullSphere ); material.SetShaderParameter( "isFullSphere", octahedralFullSphere );
material.SetShaderParameter( "imposterFrames", Vector2.One * mb.octahedralSides ); material.SetShaderParameter( "imposterFrames", Vector2.One * octahedralSides );
Materials.Set( mb.X_outputMesh, material ); Materials.Set( mb.X_outputMesh, material );
} }
@ -66,10 +70,9 @@ namespace Rokojori
} }
} }
public override void CreateBakes() public override void CreateBakers()
{ {
var fov = multiBaker.GetCameraFOV(); var fov = multiBaker.GetCameraFOV();
var distance = multiBaker.GetCameraDistance(); var distance = multiBaker.GetCameraDistance();
@ -79,16 +82,14 @@ namespace Rokojori
var mb = multiBaker; var mb = multiBaker;
_bakers.ForEach( _bakers.ForEach(
b => bk =>
{ {
b.useCustomFOV = true; var vs = bk.viewSettings;
b.customFOV = fov; vs.fovDistance = Manual_BakingFDSettings.Create( fov, distance );
b.useCustomDistance = true; vs.rotationMode = BakingViewSettings.RotationMode.Quaternion;
b.customDistance = distance;
b.rotationMode = Baker.RotationMode.Quaternion;
} }
); );
@ -96,20 +97,20 @@ namespace Rokojori
var numTextures = GetNumViews(); var numTextures = GetNumViews();
var textureAlignment = TextureMerger.ComputeTextureAlignment( numTextures ); var textureAlignment = TextureMerger.ComputeTextureAlignment( numTextures );
var toOP = 1f / ( mb.octahedralSides - 1 ); var toOP = 1f / ( octahedralSides - 1 );
var index = 0; var index = 0;
for ( int x = 0; x < mb.octahedralSides; x++ ) for ( int x = 0; x < octahedralSides; x++ )
{ {
for ( int y = 0; y < mb.octahedralSides; y++ ) for ( int y = 0; y < octahedralSides; y++ )
{ {
var inverseX = ( mb.octahedralSides - 1 ) - x; var inverseX = ( octahedralSides - 1 ) - x;
var inverseY = ( mb.octahedralSides - 1 ) - y; var inverseY = ( octahedralSides - 1 ) - y;
var octahedralPosition = new Vector2( y, inverseX ) * toOP; var octahedralPosition = new Vector2( y, inverseX ) * toOP;
var normal = OctahedralMapping.Map( octahedralPosition, mb.octahedralFullSphere ); var normal = OctahedralMapping.Map( octahedralPosition, octahedralFullSphere );
_bakers[ index ].rotationQuaternion = Math3D.LookRotation( normal, true ).Normalized().Inverse(); _bakers[ index ].viewSettings.rotationQuaternion = Math3D.LookRotation( normal, true ).Normalized().Inverse();
index ++; index ++;
} }

View File

@ -0,0 +1 @@
uid://bdgrhysvuusyp

View File

@ -0,0 +1,36 @@
using System.Collections;
using System.Collections.Generic;
using Godot;
using System;
using System.Threading.Tasks;
namespace Rokojori
{
[Tool][GlobalClass]
public partial class _XX_MultiBakeMode:Resource
{
public MultiBaker multiBaker;
public virtual int GetNumViews()
{
return -1;
}
public virtual void CreateBakers()
{
}
public virtual void AssignMaterial( BakingMaterialMode mode, Texture2D texture )
{
}
public virtual void CreateMaterial( bool preview )
{
}
}
}

View File

@ -7,7 +7,8 @@ using System.Threading.Tasks;
namespace Rokojori namespace Rokojori
{ {
public abstract class MultiBakeModeBillboardBase:MultiBakeModeImplementation [Tool][GlobalClass]
public partial class _XX_MultiBakeModeBillboardBase:_XX_MultiBakeMode
{ {
public override void CreateMaterial( bool preview ) public override void CreateMaterial( bool preview )
{ {

View File

@ -0,0 +1,48 @@
using System.Collections;
using System.Collections.Generic;
using Godot;
using System;
using System.Threading.Tasks;
namespace Rokojori
{
[Tool][GlobalClass]
public partial class _XX_Spherical_Baker:_XX_MultiBakeMode
{
public static readonly string sphericalShader = "res://addons/rokojori_action_library/External/Imposter/materials/shaders/ImpostorShader.gdshader";
[Export]
public int sphericalSides = 4;
[Export]
public int sphericalRows = 3;
[Export]
public float minPitch = -30;
[Export]
public float maxPitch = 30;
public override int GetNumViews()
{
var views = sphericalSides * sphericalRows;
return views;
}
public override void CreateMaterial( bool preview )
{
}
public override void AssignMaterial( BakingMaterialMode mode, Texture2D texture )
{
}
public override void CreateBakers()
{
}
}
}

View File

@ -0,0 +1 @@
uid://dc1xsvfdwtqbc

View File

@ -24,6 +24,9 @@ namespace Rokojori
[Export] [Export]
public bool createLayout; public bool createLayout;
[Export]
public int dilationRadius = 64;
[ExportGroup("Source")] [ExportGroup("Source")]
[Export] [Export]
@ -217,19 +220,29 @@ namespace Rokojori
for ( int i = 0; i < _textures.Count; i++ ) for ( int i = 0; i < _textures.Count; i++ )
{ {
var mesh = X_textureMergerViewport.CreateChild<CsgMesh3D>( "Texture " + ( i + 1 ) ); var meshInstance = X_textureMergerViewport.CreateChild<MeshInstance3D>( "Texture " + ( i + 1 ) );
var uvRectangle = GetUVRectangle( alignment, i ); var uvRectangle = GetUVRectangle( alignment, i );
SetMeshCoordinates( mesh, uvRectangle, i ); RJLog.Log( "Set Texture" + ( i + 1 ), uvRectangle.min, uvRectangle.max );
SetMeshCoordinates( meshInstance, uvRectangle, i );
var dilatedMaterial = new DilationDrawerMaterial();
dilatedMaterial.textureAlbedo.Set( _textures[ i ] );
dilatedMaterial.resolution.Set( _textures[ i ].GetSize() );
dilatedMaterial.maxRadius.Set( dilationRadius );
dilatedMaterial.alphaTreshold.Set( 1 );
dilatedMaterial.assignedColorAlphaMinimum.Set( 254 );
dilatedMaterial.genericAlphaOffset.Set( 0 );
dilatedMaterial.amount.Set( 1 );
var material = new StandardMaterial3D(); var material = new StandardMaterial3D();
material.Transparency = transparencyMode; material.Transparency = transparencyMode;
material.AlphaScissorThreshold = alphaThreshold; material.AlphaScissorThreshold = alphaThreshold;
material.ShadingMode = BaseMaterial3D.ShadingModeEnum.Unshaded; material.ShadingMode = BaseMaterial3D.ShadingModeEnum.Unshaded;
material.AlbedoTexture = _textures[ i ]; material.AlbedoTexture = _textures[ i ];
mesh.Material = material;
Materials.Set( meshInstance, dilatedMaterial );
} }
} }
@ -237,26 +250,36 @@ namespace Rokojori
{ {
for ( int i = 0; i < _textures.Count; i++ ) for ( int i = 0; i < _textures.Count; i++ )
{ {
var mesh = outputTarget.CreateChild<CsgMesh3D>( "Texture " + ( i + 1 ) ); var meshInstance = outputTarget.CreateChild<MeshInstance3D>( "Texture " + ( i + 1 ) );
SetMeshCoordinates( mesh, customPositions[ i ], customSizes[ i ], i ); SetMeshCoordinates( meshInstance, customPositions[ i ], customSizes[ i ], i );
var material = new StandardMaterial3D(); var material = new StandardMaterial3D();
material.Transparency = transparencyMode; material.Transparency = transparencyMode;
material.ShadingMode = BaseMaterial3D.ShadingModeEnum.Unshaded; material.ShadingMode = BaseMaterial3D.ShadingModeEnum.Unshaded;
material.AlphaScissorThreshold = alphaThreshold; material.AlphaScissorThreshold = alphaThreshold;
var dilatedMaterial = new DilationDrawerMaterial();
dilatedMaterial.textureAlbedo.Set( _textures[ i ] );
dilatedMaterial.resolution.Set( _textures[ i ].GetSize() );
dilatedMaterial.maxRadius.Set( dilationRadius );
dilatedMaterial.alphaTreshold.Set( 10 );
dilatedMaterial.assignedColorAlphaMinimum.Set( 10 );
dilatedMaterial.genericAlphaOffset.Set( 50 );
dilatedMaterial.amount.Set( 1 );
material.AlbedoTexture = _textures[ i ]; material.AlbedoTexture = _textures[ i ];
mesh.Material = material; Materials.Set( meshInstance, dilatedMaterial );
} }
} }
void SetMeshCoordinates( CsgMesh3D mesh, Box2 rectangle, int index ) void SetMeshCoordinates( MeshInstance3D mesh, Box2 rectangle, int index )
{ {
SetMeshCoordinates( mesh, rectangle.min, rectangle.max, index ); SetMeshCoordinates( mesh, rectangle.min, rectangle.max, index );
} }
void SetMeshCoordinates( CsgMesh3D mesh, Vector2 min, Vector2 max, int index ) void SetMeshCoordinates( MeshInstance3D mesh, Vector2 min, Vector2 max, int index )
{ {
var start = ConvertUVtoCameraSpace( min ); var start = ConvertUVtoCameraSpace( min );
var end = ConvertUVtoCameraSpace( max ); var end = ConvertUVtoCameraSpace( max );
@ -269,7 +292,7 @@ namespace Rokojori
mesh.GlobalPosition = new Vector3( start.X + size.X/2, start.Y + size.Y/2, -1 ); mesh.GlobalPosition = new Vector3( start.X + size.X/2, start.Y + size.Y/2, -1 );
// RJLog.Log( "Set Mesh", index, "Min:", min, ">>", start, "Max:", max, ">>", end ); RJLog.Log( "Set Mesh", index, "Size:", size, "Min:", min, ">>", start, "Max:", max, ">>", end );
} }
public static Vector2I ComputeTextureAlignment( int numElements ) public static Vector2I ComputeTextureAlignment( int numElements )

View File

@ -0,0 +1,40 @@
using System.Collections;
using System.Collections.Generic;
using Godot;
using System;
namespace Rokojori
{
[Tool]
[GlobalClass]
public partial class AutoDistance_BakingFDSettings:_XX_BakingFDSettings
{
[Export]
public float fov = 75;
[Export]
public float zoom = 1;
[Export]
public SizeEstimationType sizeEstimation = SizeEstimationType.Bounding_Sphere;
[Export]
public float sizeAbsoluteOffset = 0;
[Export]
public float sizeRelativeOffset = 0.1f;
public override Vector2 ComputeFOVDistance( float size )
{
size += sizeAbsoluteOffset;
size += sizeRelativeOffset * size;
var distance = Cameras.ComputeCameraFrameFittingDistance( fov, size / zoom );
return new Vector2( fov, distance );
}
}
}

View File

@ -0,0 +1 @@
uid://chqe2154cxijp

View File

@ -0,0 +1,45 @@
using System.Collections;
using System.Collections.Generic;
using Godot;
using System;
namespace Rokojori
{
[Tool]
[GlobalClass]
public partial class AutoFOVDistance_BakingFDSettings:_XX_BakingFDSettings
{
[Export]
public float gameCameraFOV = 75;
[Export]
public float gameViewDistance = 10;
[Export]
public float zoom = 1;
[Export]
public SizeEstimationType sizeEstimation = SizeEstimationType.Bounding_Sphere;
[Export]
public float sizeAbsoluteOffset = 0;
[Export]
public float sizeRelativeOffset = 0.1f;
public override Vector2 ComputeFOVDistance( float size )
{
size += sizeAbsoluteOffset;
size += sizeRelativeOffset * size;
var fov = Cameras.ComputeFOVForBillboard( gameCameraFOV, size, gameViewDistance );
var distance = Cameras.ComputeCameraFrameFittingDistance( fov, size / zoom );
return new Vector2( fov, distance );
}
}
}

View File

@ -0,0 +1 @@
uid://cf5kjcm27di0q

View File

@ -0,0 +1,154 @@
using System.Collections;
using System.Collections.Generic;
using Godot;
using System;
namespace Rokojori
{
[Tool]
[GlobalClass]
public partial class BakingViewSettings:Resource
{
/*public enum CameraDistanceDetectionType
{
Automatic_Distance_Detection,
Custom_Distance
}
public enum CameraFOVMode
{
Keep_Fov,
Compute_Fov_With_Distance,
Custom_Fov
}*/
[Export]
public _XX_BakingFDSettings fovDistance;
/*
[Export]
public float originalFOV = 75;
[Export]
public bool assignFOV = false;
[Export]
public float placingDistance = 500;
[Export]
public float zoom = 1;
*/
[ExportGroup( "Debug Readonly" )]
[Export]
public float _XX_ComputedFOV = 75;
[Export]
public float _XX_ComputedDistance = 1;
[Export]
public float _XX_ComputedOutputScale = 1;
/*
[ExportGroup( "Custom FOV" )]
[Export]
public bool useCustomFOV = false;
[Export]
public float customFOV = 75;
[ExportGroup( "Custom Distance" )]
[Export]
public bool useCustomDistance = false;
[Export]
public float customDistance = 50;
*/
public enum RotationMode
{
Yaw_Pitch,
Quaternion
}
[ExportGroup("Rotation")]
[Export]
public RotationMode rotationMode = RotationMode.Yaw_Pitch;
[Export( PropertyHint.Range, "-180,180")]
public float yaw = 0;
[Export( PropertyHint.Range, "-180,180")]
public float pitch = 0;
[Export]
public Quaternion rotationQuaternion;
public Quaternion bakingRotation => RotationMode.Yaw_Pitch == rotationMode ?
Math3D.YawPitchRotation( yaw, pitch ) :
rotationQuaternion;
public void ApplySettings( Camera3D camera, Node3D target, Vector3 pivot )
{
var box = target.GetWorldBounds();
if ( box == null )
{
RJLog.Log( "No target" );
return;
}
Box3 box3 = box;
box3.IncludePoint( target.ToGlobal( pivot ) );
var sphere = Sphere.ContainingBox( box3 );
var size = sphere.radius;
if ( fovDistance is AutoDistance_BakingFDSettings ad )
{
size = ad.sizeEstimation == _XX_BakingFDSettings.SizeEstimationType.Bounding_Sphere ?
sphere.radius : ( box3.size.Y / 2f );
}
if ( fovDistance is AutoFOVDistance_BakingFDSettings afd )
{
size = afd.sizeEstimation == _XX_BakingFDSettings.SizeEstimationType.Bounding_Sphere ?
sphere.radius : ( box3.size.Y / 2f );
}
var fd = fovDistance.ComputeFOVDistance( size / 2f );
_XX_ComputedDistance = fd.Y;
_XX_ComputedFOV = fd.X;
camera.Fov = fd.X;
var cameraRotation = bakingRotation;
var offset = ( Vector3.Back * _XX_ComputedDistance ) * cameraRotation ;
camera.GlobalPosition = target.GlobalPosition + offset - pivot;
camera.SetGlobalQuaternion( cameraRotation.Inverse() );
_XX_ComputedOutputScale = Cameras.ComputeCameraFittingScale( camera.Fov, _XX_ComputedDistance );
}
}
}

View File

@ -0,0 +1 @@
uid://d1mvjtf46vfip

View File

@ -0,0 +1,33 @@
using System.Collections;
using System.Collections.Generic;
using Godot;
using System;
namespace Rokojori
{
[Tool]
[GlobalClass]
public partial class Manual_BakingFDSettings:_XX_BakingFDSettings
{
[Export]
public float cameraDistance = 10;
[Export]
public float cameraFOV = 75;
public override Vector2 ComputeFOVDistance( float size )
{
return new Vector2( cameraFOV, cameraDistance );
}
public static Manual_BakingFDSettings Create( float fov, float distance )
{
var m = new Manual_BakingFDSettings();
m.cameraDistance = distance;
m.cameraFOV = fov;
return m;
}
}
}

View File

@ -0,0 +1 @@
uid://dbfheg550pyqw

View File

@ -0,0 +1,27 @@
using System.Collections;
using System.Collections.Generic;
using Godot;
using System;
namespace Rokojori
{
[Tool]
[GlobalClass]
public partial class _XX_BakingFDSettings:Resource
{
public enum SizeEstimationType
{
Bounding_Sphere,
Bounding_Box_Height
}
public virtual Vector2 ComputeFOVDistance( float size )
{
return Vector2.Zero;
}
}
}

View File

@ -0,0 +1 @@
uid://cy6khw6xl3qrg

View File

@ -791,6 +791,16 @@ namespace Rokojori
} }
} }
public void Turbulence( float amount, Vector3 noiseScale, Vector3 noiseOffset )
{
for ( int i = 0; i < vertices.Count; i++ )
{
var v = vertices[ i ];
var offset = Noise.PerlinPolar3( v * noiseScale + noiseOffset ) * amount;
vertices[ i ] = v + offset;
}
}
public void RemapX( Curve curve ) public void RemapX( Curve curve )
{ {
for ( int i = 0; i < vertices.Count; i++ ) for ( int i = 0; i < vertices.Count; i++ )
@ -821,6 +831,8 @@ namespace Rokojori
} }
} }
public void ScaleXForY( Curve curve ) public void ScaleXForY( Curve curve )
{ {
for ( int i = 0; i < vertices.Count; i++ ) for ( int i = 0; i < vertices.Count; i++ )

View File

@ -28,8 +28,8 @@ namespace Rokojori
{ {
CreateWeights(); CreateWeights();
var minPosition = Math3D.MinPosition( cornerA, cornerB ); var minPosition = Math3D.MinLocalPosition( cornerA, cornerB );
var maxPosition = Math3D.MaxPosition( cornerA, cornerB ); var maxPosition = Math3D.MaxLocalPosition( cornerA, cornerB );
if ( snapToWorldGrid ) if ( snapToWorldGrid )
{ {
@ -46,7 +46,7 @@ namespace Rokojori
if ( xzOnly ) if ( xzOnly )
{ {
var y = ( cornerA.GlobalPosition.Y + cornerB.GlobalPosition.Y ) / 2f; var y = ( cornerA.Position.Y + cornerB.Position.Y ) / 2f;
for ( int x = 0; x < pointsX; x++ ) for ( int x = 0; x < pointsX; x++ )
{ {
@ -89,6 +89,8 @@ namespace Rokojori
var p = new ScatterPoint( this, id++ ); var p = new ScatterPoint( this, id++ );
p.position = new Vector3( x, y, z ); p.position = new Vector3( x, y, z );
p.useGlobalPosition = false;
p.visible = ! setDiscarded; p.visible = ! setDiscarded;
p.seed = Noise.CreateSeed( p.position ); p.seed = Noise.CreateSeed( p.position );

View File

@ -103,6 +103,15 @@ namespace Rokojori
Dictionary<Scatterer,int> _scattererIDs = new Dictionary<Scatterer, int>(); Dictionary<Scatterer,int> _scattererIDs = new Dictionary<Scatterer, int>();
public enum PositionMode
{
Local_As_Global,
Local_Plus_ScattererGlobal
}
[Export]
public PositionMode positionMode;
public void ClearCache() public void ClearCache()
{ {
_instantiatedPoints.Clear(); _instantiatedPoints.Clear();

View File

@ -377,6 +377,32 @@ namespace Rokojori
return IndexFromUnnormalizedWeights( weights, 1 ); return IndexFromUnnormalizedWeights( weights, 1 );
} }
public List<int> Numbers( int numValues, int offset = 0 )
{
var list = new List<int>();
for ( int i = 0; i < numValues; i++ )
{
list.Add( i + offset );
}
return new RandomList<int>( list, this ).GetList();
}
public List<int> Selection( int possibleValues, int selection )
{
selection = Mathf.Min( selection, possibleValues );
var list = new List<int>();
for ( int i = 0; i < possibleValues; i++ )
{
list.Add( i );
}
return new RandomList<int>( list, this ).GetList().GetRange( 0, selection );
}
int _FindElementIndexWithWeights( List<float> weights, float value ) int _FindElementIndexWithWeights( List<float> weights, float value )
{ {
var limit = 0f; var limit = 0f;

View File

@ -16,5 +16,10 @@ namespace Rokojori
{ {
return true; return true;
} }
public static bool IsSelecting( Selector selector, Node node )
{
return selector == null || selector.Selects( node );
}
} }
} }

View File

@ -15,6 +15,16 @@ vec3 applyMatrixWithoutTranslation( vec3 v, mat4 m )
return ( mw * vec4( v, 1.0 ) ).xyz; return ( mw * vec4( v, 1.0 ) ).xyz;
} }
// L W V
// L
// W
// V
// LD WD VD
// LD
// WD
// VD
vec3 localToWorld( vec3 _VERTEX, mat4 _MODEL_MATRIX ) vec3 localToWorld( vec3 _VERTEX, mat4 _MODEL_MATRIX )
{ {
return ( _MODEL_MATRIX * vec4( _VERTEX, 1.0 ) ).xyz; return ( _MODEL_MATRIX * vec4( _VERTEX, 1.0 ) ).xyz;

View File

@ -5,7 +5,6 @@ using System.Collections.Generic;
namespace Rokojori namespace Rokojori
{ {
[Tool] [Tool]
[GlobalClass]
public partial class CustomMaterial:ShaderMaterial public partial class CustomMaterial:ShaderMaterial
{ {
public void CopyUniformsFrom( ShaderMaterial material ) public void CopyUniformsFrom( ShaderMaterial material )

View File

@ -0,0 +1,93 @@
// NOTE: Shader automatically converted from Godot Engine 4.4.stable.mono's StandardMaterial3D.
shader_type spatial;
render_mode blend_mix, depth_draw_opaque, cull_disabled, unshaded;
uniform sampler2D texture_albedo : source_color, filter_linear_mipmap, repeat_enable;
uniform vec2 resolution;
uniform int maxRadius = 32;
uniform int alphaTreshold:hint_range(1,255) = 1;
uniform int genericAlphaOffset:hint_range(0,255) = 9;
uniform int assignedColorAlphaMinimum:hint_range(0,255) = 0;
uniform float amount:hint_range(0,1)=1;
vec4 getPaddingColor( vec2 uv, vec2 pixelSize, int closestDistance, float t )
{
vec4 closestPixel = texture( texture_albedo, uv );
if ( closestPixel.a >= t )
{
return closestPixel / closestPixel.a;;
}
for ( int x = -maxRadius; x <= maxRadius; ++x )
{
for ( int y = -maxRadius; y <= maxRadius; ++y )
{
int d = x * x + y * y;
if ( d >= closestDistance )
{
continue;
}
vec2 pUV = uv + pixelSize * vec2( float( x ), float( y ) );
vec4 pixel = texture( texture_albedo, pUV );
if ( pixel.a >= t )
{
closestPixel = pixel / pixel.a;
closestPixel.a = pixel.a;
closestDistance = d;
}
}
}
return closestPixel;
}
varying vec2 pixelSize;
varying float closestDistance;
const float halfSquare = pow( 2.0, 0.5 ) * 0.5;
varying float tresholdFloat;
varying float assignedColorAlphaMinimumFloat;
varying float genericAlphaOffsetFloat;
void vertex()
{
pixelSize = vec2( 1.0 / resolution.x, 1.0 / resolution.y );
float range = float( maxRadius ) * halfSquare;
closestDistance = ( range * range + range * range );
tresholdFloat = float( alphaTreshold ) / 255.0;
assignedColorAlphaMinimumFloat = float( assignedColorAlphaMinimum ) / 255.0;
genericAlphaOffsetFloat = float( genericAlphaOffset ) / 255.0;
}
void fragment()
{
vec2 pixelPerfectUV = round( UV * resolution ) / resolution;
vec4 original = texture( texture_albedo, pixelPerfectUV );
if ( original.a == 1.0 )
{
ALBEDO = original.rgb;
ALPHA = original.a;
}
else
{
int closestDistanceInteger = int( closestDistance );
vec4 outputColor = getPaddingColor( pixelPerfectUV, pixelSize, closestDistanceInteger, tresholdFloat );
outputColor.a = max( original.a, outputColor.a > 0.0 ? assignedColorAlphaMinimumFloat : 0.0 );
ALBEDO = mix( original.rgb, outputColor.rgb, amount );
ALPHA = mix( original.a, min( 1, outputColor.a + genericAlphaOffsetFloat ), amount );
}
}

View File

@ -0,0 +1 @@
uid://cpe2qaooyu4rx

View File

@ -0,0 +1,53 @@
using Godot;
namespace Rokojori
{
// Generated by ShaderClassGenerator
public class DilationDrawerShader
{
public static readonly CachedResource<Shader> shader = new CachedResource<Shader>(
"res://addons/rokojori_action_library/Runtime/Shading/Shaders/Baking/DilationDrawer.gdshader"
);
public static readonly Texture2DPropertyName textureAlbedo = Texture2DPropertyName.Create( "texture_albedo" );
public static readonly Vector2PropertyName resolution = Vector2PropertyName.Create( "resolution" );
public static readonly IntPropertyName maxRadius = IntPropertyName.Create( "maxRadius" );
public static readonly IntPropertyName alphaTreshold = IntPropertyName.Create( "alphaTreshold" );
public static readonly IntPropertyName genericAlphaOffset = IntPropertyName.Create( "genericAlphaOffset" );
public static readonly IntPropertyName assignedColorAlphaMinimum = IntPropertyName.Create( "assignedColorAlphaMinimum" );
public static readonly FloatPropertyName amount = FloatPropertyName.Create( "amount" );
}
[Tool]
public partial class DilationDrawerMaterial:CustomMaterial
{
public static readonly CachedResource<DilationDrawerMaterial> DepthMap = CustomMaterial.Cached<DilationDrawerMaterial>(
"res://addons/rokojori_action_library/Runtime/Shading/Shaders/Baking/DepthMap.material"
);
public readonly CustomMaterialProperty<Texture2D> textureAlbedo;
public readonly CustomMaterialProperty<Vector2> resolution;
public readonly CustomMaterialProperty<int> maxRadius;
public readonly CustomMaterialProperty<int> alphaTreshold;
public readonly CustomMaterialProperty<int> genericAlphaOffset;
public readonly CustomMaterialProperty<int> assignedColorAlphaMinimum;
public readonly CustomMaterialProperty<float> amount;
public DilationDrawerMaterial()
{
Shader = DilationDrawerShader.shader.Get();
textureAlbedo = new CustomMaterialProperty<Texture2D>( this, DilationDrawerShader.textureAlbedo );
resolution = new CustomMaterialProperty<Vector2>( this, DilationDrawerShader.resolution );
maxRadius = new CustomMaterialProperty<int>( this, DilationDrawerShader.maxRadius );
alphaTreshold = new CustomMaterialProperty<int>( this, DilationDrawerShader.alphaTreshold );
genericAlphaOffset = new CustomMaterialProperty<int>( this, DilationDrawerShader.genericAlphaOffset );
assignedColorAlphaMinimum = new CustomMaterialProperty<int>( this, DilationDrawerShader.assignedColorAlphaMinimum );
amount = new CustomMaterialProperty<float>( this, DilationDrawerShader.amount );
}
}
}

View File

@ -0,0 +1 @@
uid://dq3gkhoapw0ad

View File

@ -49,7 +49,6 @@ namespace Rokojori
} }
[Tool] [Tool]
[GlobalClass]
public partial class QuadBillboardMaterial:CustomMaterial public partial class QuadBillboardMaterial:CustomMaterial
{ {

View File

@ -25,7 +25,6 @@ namespace Rokojori
} }
[Tool] [Tool]
[GlobalClass]
public partial class FancyOutlineMaterial:CustomMaterial public partial class FancyOutlineMaterial:CustomMaterial
{ {
public static readonly CachedResource<FancyOutlineMaterial> ScanWhite500Ms20x = CustomMaterial.Cached<FancyOutlineMaterial>( public static readonly CachedResource<FancyOutlineMaterial> ScanWhite500Ms20x = CustomMaterial.Cached<FancyOutlineMaterial>(

View File

@ -20,7 +20,6 @@ namespace Rokojori
} }
[Tool] [Tool]
[GlobalClass]
public partial class FresnelOverlayMaterial:CustomMaterial public partial class FresnelOverlayMaterial:CustomMaterial
{ {

View File

@ -22,7 +22,6 @@ namespace Rokojori
} }
[Tool] [Tool]
[GlobalClass]
public partial class OutlineMaterial:CustomMaterial public partial class OutlineMaterial:CustomMaterial
{ {
public static readonly CachedResource<OutlineMaterial> BoldYellow = CustomMaterial.Cached<OutlineMaterial>( public static readonly CachedResource<OutlineMaterial> BoldYellow = CustomMaterial.Cached<OutlineMaterial>(

View File

@ -17,7 +17,6 @@ namespace Rokojori
} }
[Tool] [Tool]
[GlobalClass]
public partial class OverlayMaterial:CustomMaterial public partial class OverlayMaterial:CustomMaterial
{ {

View File

@ -29,7 +29,6 @@ namespace Rokojori
} }
[Tool] [Tool]
[GlobalClass]
public partial class ScanGradientMaterial:CustomMaterial public partial class ScanGradientMaterial:CustomMaterial
{ {
public static readonly CachedResource<ScanGradientMaterial> White = CustomMaterial.Cached<ScanGradientMaterial>( public static readonly CachedResource<ScanGradientMaterial> White = CustomMaterial.Cached<ScanGradientMaterial>(

View File

@ -20,7 +20,6 @@ namespace Rokojori
} }
[Tool] [Tool]
[GlobalClass]
public partial class TriPlanarOverlayMaterial:CustomMaterial public partial class TriPlanarOverlayMaterial:CustomMaterial
{ {
public static readonly CachedResource<TriPlanarOverlayMaterial> BlueShield = CustomMaterial.Cached<TriPlanarOverlayMaterial>( public static readonly CachedResource<TriPlanarOverlayMaterial> BlueShield = CustomMaterial.Cached<TriPlanarOverlayMaterial>(

View File

@ -24,7 +24,6 @@ namespace Rokojori
} }
[Tool] [Tool]
[GlobalClass]
public partial class FadeWipeMaterial:CustomMaterial public partial class FadeWipeMaterial:CustomMaterial
{ {

View File

@ -15,7 +15,6 @@ namespace Rokojori
} }
[Tool] [Tool]
[GlobalClass]
public partial class ${ShaderName}Material:CustomMaterial public partial class ${ShaderName}Material:CustomMaterial
{ {
${MaterialPresets} ${MaterialPresets}

View File

@ -0,0 +1,54 @@
using System.Collections.Generic;
namespace Rokojori
{
public class QueueList<T>:List<T>
{
List<T> _queuedInsertions = new List<T>();
List<T> _queuedRemovals = new List<T>();
public void QueueInsert( T t )
{
_queuedInsertions.Add( t );
}
public void QueueRemoval( T t )
{
_queuedRemovals.Add( t );
}
public void IterateAndResolve( System.Action<T> callback )
{
ResolveRemovalsQueue();
ResolveInsertionQueue();
this.ForEach( t => callback( t ) );
ResolveRemovalsQueue();
}
protected void ResolveInsertionQueue()
{
if ( _queuedInsertions.Count == 0 )
{
return;
}
AddRange( _queuedInsertions );
_queuedInsertions.Clear();
}
protected void ResolveRemovalsQueue()
{
if ( _queuedRemovals.Count == 0 )
{
return;
}
Lists.RemoveRange( this, _queuedRemovals );
_queuedRemovals.Clear();
}
}
}

View File

@ -0,0 +1 @@
uid://cbec0e07mfxps

View File

@ -50,16 +50,31 @@ namespace Rokojori
float _lastTimeScale = 1; float _lastTimeScale = 1;
QueueList<System.Action> _processCallbacks = new QueueList<System.Action>();
public override void _Process( double delta ) public override void _Process( double delta )
{ {
UpdateRealTime( delta ); UpdateRealTime( delta );
if ( ! Engine.IsEditorHint() && gametimeTimeline != null ) if ( ! Engine.IsEditorHint() && gametimeTimeline != null )
{ {
Engine.TimeScale = gametimeTimeline.runner.modulatedSpeed; Engine.TimeScale = GetRunner( gametimeTimeline ).modulatedSpeed;
} }
_runners.ForEach( r => r.UpdateTimeLine( unscaledTimeDelta ) ); _runners.ForEach( r => r.UpdateTimeLine( unscaledTimeDelta ) );
_processCallbacks.IterateAndResolve( t => t() );
}
public void AddProcessCallback( System.Action a )
{
_processCallbacks.QueueInsert( a );
}
public void RemoveProcessCallback( System.Action a )
{
_processCallbacks.QueueRemoval( a );
} }
public int GetTimeLineIndex( TimeLine timeLine ) public int GetTimeLineIndex( TimeLine timeLine )

View File

@ -16,7 +16,6 @@ namespace Rokojori
} }
[Tool] [Tool]
[GlobalClass]
public partial class UINinePatchMaterial:CustomMaterial public partial class UINinePatchMaterial:CustomMaterial
{ {

View File

@ -32,7 +32,6 @@ namespace Rokojori
} }
[Tool] [Tool]
[GlobalClass]
public partial class RoundedRectangleMaterial:CustomMaterial public partial class RoundedRectangleMaterial:CustomMaterial
{ {