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