Skip to content

Commit

Permalink
Adding short/long duration features
Browse files Browse the repository at this point in the history
  • Loading branch information
dbirman committed Feb 11, 2024
1 parent 959cfe3 commit 1bc884e
Show file tree
Hide file tree
Showing 9 changed files with 5,795 additions and 5,656 deletions.
10 changes: 10 additions & 0 deletions Unity/Assets/AddressableAssetsData/link.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<linker>
<assembly fullname="Unity.Addressables, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" preserve="all">
<type fullname="UnityEngine.AddressableAssets.Addressables" preserve="all" />
</assembly>
<assembly fullname="Unity.ResourceManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" preserve="all">
<type fullname="UnityEngine.ResourceManagement.ResourceProviders.InstanceProvider" preserve="all" />
<type fullname="UnityEngine.ResourceManagement.ResourceProviders.LegacyResourcesProvider" preserve="all" />
<type fullname="UnityEngine.ResourceManagement.ResourceProviders.SceneProvider" preserve="all" />
</assembly>
</linker>
7 changes: 7 additions & 0 deletions Unity/Assets/AddressableAssetsData/link.xml.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11,274 changes: 5,638 additions & 5,636 deletions Unity/Assets/Data/dataSO.asset

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Unity/Assets/Scripts/NPUltraData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ public class NPUltraData : ScriptableObject
public string[] Areas;
public Color[] Colors;
public Vector3[] Coords;
public bool[] ShortDuration;
public bool[] SmallFootprint;
}
82 changes: 71 additions & 11 deletions Unity/Assets/Scripts/NPUltraRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class NPUltraRuntime : MonoBehaviour

private void Start()
{
_cosmosNodes = new List<OntologyNode>();

#if !UNITY_EDITOR && UNITY_WEBGL
WebGLInput.captureAllKeyboardInput = false;
Expand Down Expand Up @@ -93,28 +94,63 @@ public void LoadData()
_loaded = true;
}

public void Search(string searchStr)
public void Search(string state)
{
if (!_loaded) return;

if (searchStr != "")
State curState = JsonUtility.FromJson<State>(state);

bool activeArea = curState.search != "";
bool disabledDur = !curState.duration_long || !curState.duration_short;
bool disabledWave = !curState.footprint_large || !curState.footprint_small;

// Set neurons to active/inactive state
if (activeArea || disabledDur || disabledWave)
{
int[] searched = new int[_data.Areas.Length];

for (int i = 0; i < searched.Length; i++)
{
// For each unit, check if:
// we are searching for areas AND this is in that area, or we aren't searching for areas
// we are searching for short AND this is short
// we are searching for long AND this is long
// etc...

bool inArea = !activeArea || (activeArea && _data.Areas[i].Contains(curState.search));
bool isShort = curState.duration_short && _data.ShortDuration[i];
bool isLong = curState.duration_long && !_data.ShortDuration[i];
bool isSmall = curState.footprint_small && _data.SmallFootprint[i];
bool isLarge = curState.footprint_large && !_data.SmallFootprint[i];

bool active = inArea && (isShort || isLong) && (isSmall || isLarge);

searched[i] = active ? 1 : -1;
}

_meshManager.SetSearched(_data.Names, searched);
}
else
{
_meshManager.SetSearched(_data.Names, 0);
}

// Handle showing and hiding 3D areas
if (activeArea)
{
// Hide cosmos areas
foreach (OntologyNode node in _cosmosNodes)
node.SetVisibility(false, OntologyNode.OntologyNodeSide.Full);

// Hide the previous searched node
_searchedNode.SetVisibility(false, OntologyNode.OntologyNodeSide.Full);
if (_searchedNode != null)
_searchedNode.SetVisibility(false, OntologyNode.OntologyNodeSide.Full);

// Make the searched area visible
_rootNode.SetVisibility(true, OntologyNode.OntologyNodeSide.Full);
_searchedNode = BrainAtlasManager.ActiveReferenceAtlas.Ontology.ID2Node(
BrainAtlasManager.ActiveReferenceAtlas.Ontology.Acronym2ID(searchStr));
BrainAtlasManager.ActiveReferenceAtlas.Ontology.Acronym2ID(curState.search));
LoadNode(_searchedNode, 0.15f);

// Resize neurons
int[] searched = _data.Areas.Select(x => x.Contains(searchStr) ? 1 : -1).ToArray();
_meshManager.SetSearched(_data.Names, searched);
}
else
{
Expand All @@ -124,9 +160,8 @@ public void Search(string searchStr)

// Make the searched area visible
_rootNode.SetVisibility(false, OntologyNode.OntologyNodeSide.Full);
_searchedNode.SetVisibility(false, OntologyNode.OntologyNodeSide.Full);

_meshManager.SetSearched(_data.Names, 0);
if (_searchedNode != null)
_searchedNode.SetVisibility(false, OntologyNode.OntologyNodeSide.Full);
}
}

Expand Down Expand Up @@ -157,6 +192,24 @@ public void Select(string selectedName)
}
}

public struct State
{
//var state = {
// selected: -1, // 1 to N
// search: '', // area acronym
// footprint_small: true, // -1 short, 1 long, 0 both
// footprint_large: true, // -1 small, 1 big, 0 both
// duration_short: true,
// duration_long: true,
//};
public int selected;
public string search;
public bool footprint_small;
public bool footprint_large;
public bool duration_short;
public bool duration_long;
}

#if UNITY_EDITOR
public class DataProcessing
{
Expand All @@ -176,6 +229,8 @@ public static void ProcessCSV()
List<Color> colors = new();
List<string> namesList = new();
List<string> areaList = new();
List<bool> durationList = new();
List<bool> footprintList = new();

// skip the first row (header) and last row (blank)
for (int i = 1; i < (rows.Length - 1); i++)
Expand All @@ -197,12 +252,17 @@ public static void ProcessCSV()
areaList.Add(columns[3]);
colors.Add(HexToColor(columns[4]));
namesList.Add(i.ToString());

durationList.Add(bool.Parse(columns[6]));
footprintList.Add(bool.Parse(columns[7]));
}

dataSO.Names = namesList.ToArray();
dataSO.Coords = coords.ToArray();
dataSO.Colors = colors.ToArray();
dataSO.Areas = areaList.ToArray();
dataSO.ShortDuration = durationList.ToArray();
dataSO.SmallFootprint = footprintList.ToArray();
}
else
{
Expand Down
Binary file modified build/Build/build.data.unityweb
Binary file not shown.
Binary file modified build/Build/build.framework.js.unityweb
Binary file not shown.
Binary file modified build/Build/build.wasm.unityweb
Binary file not shown.
76 changes: 67 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,14 @@
</div>
</div>
<div class="mid-col-top-row-right">
<button class="button" onclick="footprint(true);">Small footprint</button>
<button class="button" onclick="footprint(false);">Large footprint</button>
<button class="button" onclick="duration(true);">Short duration</button>
<button class="button" onclick="duration(false);">Long duration</button>
<div>
<button class="button" id="smallFootprintButton" onclick="footprint(true);">Small footprint</button>
<button class="button" id="largeFootprintButton" onclick="footprint(false);">Large footprint</button>
</div>
<div>
<button class="button" id="shortDurationButton" onclick="duration(true);">Short duration</button>
<button class="button" id="longDurationButton" onclick="duration(false);">Long duration</button>
</div>
</div>
</div>

Expand Down Expand Up @@ -311,10 +315,12 @@

<script>
var state = {
selected: -1,
search: '',
footprint: 0,
duration: 0,
selected: -1, // 1 to N
search: '', // area acronym
footprint_small: true, // -1 short, 1 long, 0 both
footprint_large: true, // -1 small, 1 big, 0 both
duration_short: true,
duration_long: true,
};
var N;
var myGameInstance;
Expand Down Expand Up @@ -541,13 +547,65 @@
////////////////////////////////
// FOOTPRINT / DURATION //////////
////////////////////////////////
var default_button_color = '#add8e6'
var small_fp_button = document.getElementById('smallFootprintButton');
var large_fp_button = document.getElementById('largeFootprintButton');
var short_dur_button = document.getElementById('shortDurationButton');
var long_dur_button = document.getElementById('longDurationButton');

function footprint(small) {
if (small) {
state.footprint_small = !state.footprint_small;
}
else {
state.footprint_large = !state.footprint_large;
}

myGameInstance.SendMessage('main', 'Search', JSON.stringify(state));
updateFPDurButtons();
}

function duration(short) {

if (short) {
state.duration_short = !state.duration_short;
}
else {
state.duration_long = !state.duration_long;
}

myGameInstance.SendMessage('main', 'Search', JSON.stringify(state));
updateFPDurButtons();
}

function updateFPDurButtons() {
if (state.footprint_small) {
small_fp_button.style.backgroundColor = default_button_color;
}
else {
small_fp_button.style.backgroundColor = '#808080';
}

if (state.footprint_large) {
large_fp_button.style.backgroundColor = default_button_color;
}
else {
large_fp_button.style.backgroundColor = '#808080';
}

if (state.duration_long) {
long_dur_button.style.backgroundColor = default_button_color;
}
else {
long_dur_button.style.backgroundColor = '#808080';
}

if (state.duration_short) {
short_dur_button.style.backgroundColor = default_button_color;
}
else {
short_dur_button.style.backgroundColor = '#808080';
}
}

////////////////////////////////
Expand Down Expand Up @@ -575,7 +633,7 @@
document.getElementById('loadingOverlay').style.display = 'none';

if (state.search != prevSearch) {
myGameInstance.SendMessage('main', 'Search', state.search);
myGameInstance.SendMessage('main', 'Search', JSON.stringify(state));
prevSearch = state.search;

if (state.search == '') {
Expand Down

0 comments on commit 1bc884e

Please sign in to comment.