Improved receptor, percepoid sleep
This commit is contained in:
parent
21751f8cea
commit
dc8ac7ef9b
@ -52,6 +52,7 @@
|
||||
<Compile Include="Assets/Scenes/Boids/Scripts/SwarmSpawner.cs" />
|
||||
<Compile Include="Assets/NanoBrain/Perceptoid.cs" />
|
||||
<Compile Include="Assets/NanoBrain/NeuroidBehaviour.cs" />
|
||||
<Compile Include="Assets/NanoBrain/Receptor.cs" />
|
||||
<Compile Include="Assets/NanoBrain/NanoBrain.cs" />
|
||||
<Compile Include="Assets/NanoBrain/SensoryNeuroid.cs" />
|
||||
<Compile Include="Assets/NanoBrain/VisualEditor/NanoBrainComponent.cs" />
|
||||
|
||||
@ -63,7 +63,8 @@ public class Perception : Nucleus {
|
||||
if (sensoryNeuroids[i] == null)
|
||||
availableIx = i;
|
||||
else if (sensoryNeuroids[i].receptor.thingType == thingId) {
|
||||
sensoryNeuroids[i].receptor.position = localPosition;
|
||||
//sensoryNeuroids[i].receptor.position = localPosition;
|
||||
sensoryNeuroids[i].receptor.ProcessStimulus(999, localPosition);
|
||||
return;
|
||||
}
|
||||
if (availableIx == -1) {
|
||||
@ -101,7 +102,8 @@ public class Perception : Nucleus {
|
||||
receiver.neuroid.GetInputFrom(neuroid.velocityNeuroid);
|
||||
}
|
||||
|
||||
neuroid.receptor.position = localPosition;
|
||||
//neuroid.receptor.position = localPosition;
|
||||
neuroid.receptor.ProcessStimulus(333, localPosition);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -127,7 +127,7 @@ public class Perceptoid : Neuroid {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void ProcessStimulus(NanoBrainObj brain, int thingType, Vector3 lcoalPosition) {
|
||||
public static void ProcessStimulus(NanoBrainObj brain, int thingType, Vector3 localPosition) {
|
||||
Perceptoid selectedPerceptoid = null;
|
||||
foreach (Perceptoid nucleus in brain.perceptei) {
|
||||
if (nucleus is Perceptoid perceptoid && (thingType == 0 || perceptoid.thingType == thingType))
|
||||
@ -144,7 +144,8 @@ public class Perceptoid : Neuroid {
|
||||
Debug.Log("No perceptoid selected, stimulus is ignored");
|
||||
return;
|
||||
}
|
||||
selectedPerceptoid.receptor.position = lcoalPosition;
|
||||
//selectedPerceptoid.receptor.position = localPosition;
|
||||
selectedPerceptoid.receptor.ProcessStimulus(888, localPosition);
|
||||
}
|
||||
public static Receptor GetReceptor(NanoBrainObj brain, int thingType) {
|
||||
foreach (Perceptoid perceptoid in brain.perceptei) {
|
||||
|
||||
33
Assets/NanoBrain/Receptor.cs
Normal file
33
Assets/NanoBrain/Receptor.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class Receptor {
|
||||
|
||||
public Neuroid neuroid;
|
||||
public List<Perceptoid> perceptoids;
|
||||
|
||||
public int thingId;
|
||||
public int thingType;
|
||||
public Vector3 localPosition;
|
||||
|
||||
/// <summary>
|
||||
/// Local position of the thing
|
||||
/// </summary>
|
||||
public virtual Vector3 position {
|
||||
get {
|
||||
return this.localPosition;
|
||||
}
|
||||
// set {
|
||||
// this.localPosition = value;
|
||||
// neuroid.UpdateState();
|
||||
// }
|
||||
}
|
||||
|
||||
public virtual void ProcessStimulus(int thingId, Vector3 localPosition) {
|
||||
this.thingId = thingId;
|
||||
this.localPosition = localPosition;
|
||||
neuroid.UpdateState();
|
||||
//perceptoids[0].UpdateState();
|
||||
}
|
||||
}
|
||||
2
Assets/NanoBrain/Receptor.cs.meta
Normal file
2
Assets/NanoBrain/Receptor.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cfb9734aebc3ab85aacf87d26fb92e55
|
||||
@ -1,26 +1,36 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class Receptor {
|
||||
// public class Receptor {
|
||||
|
||||
public Neuroid neuroid;
|
||||
// public Neuroid neuroid;
|
||||
// public List<Perceptoid> perceptoids;
|
||||
|
||||
public int thingType;
|
||||
public Vector3 localPosition;
|
||||
// public int thingId;
|
||||
// public int thingType;
|
||||
// public Vector3 localPosition;
|
||||
|
||||
/// <summary>
|
||||
/// Local position of the thing
|
||||
/// </summary>
|
||||
public virtual Vector3 position {
|
||||
get {
|
||||
return this.localPosition;
|
||||
}
|
||||
set {
|
||||
this.localPosition = value;
|
||||
neuroid.UpdateState();
|
||||
}
|
||||
}
|
||||
}
|
||||
// /// <summary>
|
||||
// /// Local position of the thing
|
||||
// /// </summary>
|
||||
// public virtual Vector3 position {
|
||||
// get {
|
||||
// return this.localPosition;
|
||||
// }
|
||||
// set {
|
||||
// this.localPosition = value;
|
||||
// neuroid.UpdateState();
|
||||
// }
|
||||
// }
|
||||
|
||||
// public virtual void ProcessStimulus(int thingId, Vector3 localPosition) {
|
||||
// this.thingId = thingId;
|
||||
// this.localPosition = localPosition;
|
||||
// neuroid.UpdateState();
|
||||
|
||||
// }
|
||||
// }
|
||||
|
||||
public class SensoryNeuroid : Neuroid {
|
||||
// A neuroid which has no neurons as input
|
||||
@ -32,6 +42,7 @@ public class SensoryNeuroid : Neuroid {
|
||||
this.name = name + ": position";
|
||||
this.receptor = new Receptor {
|
||||
neuroid = this,
|
||||
//perceptoids[0] = this,
|
||||
thingType = thingId
|
||||
};
|
||||
this.velocityNeuroid = new(brain, name + ": velocity");
|
||||
@ -111,7 +122,7 @@ public class VelocityNeuroid : Neuroid {
|
||||
this.stale = 0;
|
||||
|
||||
//foreach (Neuroid receiver in receivers)
|
||||
foreach(Receiver receiver in receivers) {
|
||||
foreach (Receiver receiver in receivers) {
|
||||
if (receiver.nucleus is Neuroid neuroid)
|
||||
neuroid.SetInput(this);
|
||||
}
|
||||
|
||||
@ -35,6 +35,11 @@ public class NanoBrainObj : ScriptableObject, ISerializationCallbackReceiver {
|
||||
if (nucleus.isSleeping)
|
||||
nucleus.outputValue = Vector3.zero;
|
||||
}
|
||||
foreach (Perceptoid perception in perceptei) {
|
||||
perception.stale++;
|
||||
if (perception.isSleeping)
|
||||
perception.outputValue = Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnBeforeSerialize() {
|
||||
|
||||
@ -41,9 +41,8 @@ public class Boid : MonoBehaviour {
|
||||
Vector3 localPosition = this.transform.InverseTransformPoint(neighbour.transform.position);
|
||||
//Debug.DrawRay(this.transform.position, this.transform.TransformDirection(localPosition), Color.magenta);
|
||||
|
||||
//int thingId = neighbour.GetInstanceID();
|
||||
// nanoBrain.perception.ProcessStimulus(thingId, BoidType, localPosition, neighbour.gameObject.name);
|
||||
boidReceptor.position = localPosition;
|
||||
int thingId = neighbour.GetInstanceID();
|
||||
boidReceptor.ProcessStimulus(thingId, localPosition);
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,7 +51,7 @@ public class Boid : MonoBehaviour {
|
||||
Vector3 pointOnBounds = innerBounds.ClosestPoint(point);
|
||||
Vector3 desiredWorldSpace = (pointOnBounds - point).normalized * sc.speed;
|
||||
Vector3 desiredLocalSpace = -this.transform.InverseTransformPoint(desiredWorldSpace);
|
||||
boundaryReceptor.position = desiredLocalSpace;
|
||||
boundaryReceptor.ProcessStimulus(777, desiredLocalSpace);
|
||||
}
|
||||
|
||||
Vector3 worldForce = this.transform.TransformDirection(nanoBrain.root.outputValue);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user