rj-action-library/Runtime/Procedural/Scatter/ScatterPoint.cs

90 lines
1.9 KiB
C#

using System.Collections;
using System.Collections.Generic;
using Godot;
using System;
namespace Rokojori
{
public class ScatterPoint
{
protected Scatterer _creator;
public Scatterer creator => _creator;
protected int _creatorID;
public int creatorID => _creatorID;
public ScatterPoint( Scatterer creator, int id )
{
this._creator = creator;
this._creatorID = id;
}
public bool visible = false;
public Vector3 position = Vector3.Zero;
public bool useGlobalPosition = true;
public Quaternion rotation = Quaternion.Identity;
public bool useGlobalRotation = true;
public Vector3 scale = Vector3.One;
public PackedScene scene;
public Node3D parent;
public int seed;
public Vector3 globalPosition => useGlobalPosition || parent == null ?
position : parent.ToGlobal( position );
public bool CanBeReusedBy( ScatterPoint other )
{
return parent == other.parent && scene == other.scene;
}
public void UpdateInstantiated( Node3D node )
{
ApplyTransform( node );
}
public Node3D Instantiate()
{
if ( ! visible || scene == null || parent == null )
{
return null;
}
var node3D = scene.Instantiate<Node3D>();
parent.AddChild( node3D );
node3D.Owner = parent.Owner;
ApplyTransform( node3D );
return node3D;
}
void ApplyTransform( Node3D node3D )
{
if ( useGlobalPosition )
{
node3D.GlobalPosition = position;
}
else
{
node3D.Position = position;
}
if ( useGlobalRotation )
{
Math3D.SetGlobalRotationTo( node3D, rotation );
}
else
{
node3D.Quaternion = rotation;
}
node3D.Scale = scale;
}
}
}