01/02 : SNN Visualization(without MagicLeap) (1)
Working hour : 15:15- 16:30 / 19:00-23:30
Works to do
1. SNN Visualization model
2. Arrows on window
a. check the plane finding function can recognize the window
1. SNN visualization model
section을 구분해서 node 가 선택되도록 제작.
line이 한번에 보여 모델이 초라해 보임.
깜박깜박 하는 이펙트가 들어가도록 수정할 것.
works for tommorrow
섹션 3*3으로 구분하기
입력 node 개수에 따라 출력여부 결정하기
이펙트 추가
answerblock 구현
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class _201231_1 : MonoBehaviour
{
//1: using line renderer
private LineRenderer lineRenderer;
public float lineDrawSpeed = 6f;
public GameObject Line;
List<List<GameObject>> lines_1 = new List<List<GameObject>>();
List<List<GameObject>> lines_2 = new List<List<GameObject>>();
List<List<GameObject>> lines_3 = new List<List<GameObject>>();
//2: node & blocks & answerblocks
public int numb;
public List<GameObject> ansblock = new List<GameObject>();
public GameObject Node;
public GameObject BBlock;
public GameObject WBlock;
List<GameObject> Node_1 = new List<GameObject>();
List<GameObject> Node_2 = new List<GameObject>();
List<GameObject> Node_3 = new List<GameObject>();
List<GameObject> BlockList = new List<GameObject>();
/*
//3: using controller
private MLInput.Controller _controller;
*/
//4: others
private Dictionary<int, List<int>> numData = new Dictionary<int, List<int>>();
List<List<int>> nodeinfo_12 = new List<List<int>>();
List<List<int>> nodeinfo_23 = new List<List<int>>();
int targetnumb;
// Start is called before the first frame update
void Start()
{
/*MLInput.Start();
MLInput.OnControllerButtonDown += OnButtonDown;
_controller = MLInput.GetController(MLInput.Hand.Right);
*/
numData.Add(0, new List<int> { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0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 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 });
numData.Add(8, new List<int> { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 });
numData.Add(9, new List<int> { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 });
// Initial blocks & nodes construction
for (int row = 0; row < 10; row++)
{
for (int col = 0; col < 10; col++)
{
GameObject _obj_3 = Instantiate(BBlock, new Vector3(-2f, 0.4f * row - 2.0f, 0.4f * col + 4.5f), Quaternion.identity);
BlockList.Add(_obj_3);
}
}
float ran_x, ran_y, ran_z;
for (int i = 0; i < numb; i++)
{
ran_x = Random.Range(-1.8f, 0.25f);
ran_y = Random.Range(-1.5f, 1.5f);
ran_z = Random.Range(3.8f, 9.2f);
GameObject _obj_1 = Instantiate(Node, new Vector3(ran_x, ran_y, ran_z), Quaternion.identity);
Node_1.Add(_obj_1);
ran_x = Random.Range(-0.25f, 2.275f);
ran_y = Random.Range(-1.5f, 1.5f);
ran_z = Random.Range(3.8f, 9.2f);
GameObject _obj_2 = Instantiate(Node, new Vector3(ran_x, ran_y, ran_z), Quaternion.identity);
Node_2.Add(_obj_2);
ran_x = Random.Range(2.275f, 4.3f);
ran_y = Random.Range(-1.5f, 1.5f);
ran_z = Random.Range(3.8f, 9.2f);
GameObject _obj_3 = Instantiate(Node, new Vector3(ran_x, ran_y, ran_z), Quaternion.identity);
Node_3.Add(_obj_3);
}
Debug.Log("Done");
}
// Update is called once per frame
void Update()
{
/*
* Convert the content
*
void OnDestroy()
{
MLInput.OnControllerButtonDown -= OnButtonDown;
MLInput.Stop();
}
void OnButtonDown(byte controllereld, MLInput.Controller.Button button)
{
if(button == MLInput.Controller.Button.HomeTap)
{
}
}
*/
if (Input.GetMouseButtonDown(0))
{
for (int i = numb - 1; i >= 0; i--)
{
Destroy(Node_1[i]);
Destroy(Node_2[i]);
Destroy(Node_3[i]);
}
for (int j = 99; j >= 0; j--)
{
Destroy(BlockList[j]);
}
int len = lines_1.Count;
for (int k = len - 1; k >= 0; k--)
{
for (int a = lines_1[k].Count - 1; a >= 0; a--)
Destroy(lines_1[k][a]);
lines_1[k].Clear();
}
len = lines_2.Count;
for (int k = len - 1; k >= 0; k--)
{
for (int a = lines_2[k].Count - 1; a >= 0; a--)
Destroy(lines_2[k][a]);
lines_2[k].Clear();
}
len = lines_3.Count;
for (int k = len - 1; k >= 0; k--)
{
for (int a = lines_3[k].Count - 1; a >= 0; a--)
Destroy(lines_3[k][a]);
lines_3[k].Clear();
}
Node_1.Clear();
Node_2.Clear();
Node_3.Clear();
BlockList.Clear();
lines_1.Clear();
lines_2.Clear();
lines_3.Clear();
gamecontrol();
}
}
void gamecontrol()
{
targetnumb = Random.Range(0, 10);
// create new numb plane
drawplane();
// create new nodes
float ran_x, ran_y, ran_z;
for (int i = 0; i < numb; i++)
{
ran_x = Random.Range(-1.8f, 0.25f);
ran_y = Random.Range(-1.5f, 1.5f);
ran_z = Random.Range(3.8f, 9.2f);
GameObject _obj_1 = Instantiate(Node, new Vector3(ran_x, ran_y, ran_z), Quaternion.identity);
Node_1.Add(_obj_1);
ran_x = Random.Range(-0.25f, 2.275f);
ran_y = Random.Range(-1.5f, 1.5f);
ran_z = Random.Range(3.8f, 9.2f);
GameObject _obj_2 = Instantiate(Node, new Vector3(ran_x, ran_y, ran_z), Quaternion.identity);
Node_2.Add(_obj_2);
ran_x = Random.Range(2.275f, 4.3f);
ran_y = Random.Range(-1.5f, 1.5f);
ran_z = Random.Range(3.8f, 9.2f);
GameObject _obj_3 = Instantiate(Node, new Vector3(ran_x, ran_y, ran_z), Quaternion.identity);
Node_3.Add(_obj_3);
}
select_node();
section_node();
//change_node();
}
//시냅스 연결과정
void select_node()
{
//Number plane ~ 1st node
for (int i = 0; i < 100; i++)
{
for (int j = 0; j < numb; j++)
{
if (numData[targetnumb][i] == 1)
{
if ((Vector3.Distance(new Vector3(BlockList[i].transform.position.x, BlockList[i].transform.position.y, BlockList[i].transform.position.z), new Vector3(BlockList[i].transform.position.x, Node_1[j].transform.position.y, Node_1[j].transform.position.z)) < .5f)&& (BlockList[i].transform.position.x- Node_1[j].transform.position.x) <.8f)
{
changeOBcolor(Node_1[j], 0);
}
}
}
}
//1st node ~ 2nd node
int nodenumrand, nodenewrand;
GameObject temp;
for(int i=0; i<numb; i++)
{
nodeinfo_12.Add(new List<int>());
lines_1.Add(new List<GameObject>());
nodenumrand = Random.Range(0, 4);
for(int j=0; j<nodenumrand; j++)
{
nodenewrand = Random.Range(0, numb);
nodeinfo_12[i].Add(nodenewrand);
temp = drawline(Node_1[i].transform.position, Node_2[nodenewrand].transform.position,0);
lines_1[i].Add(temp);
}
}
//2nd node ~ 3rd node
for (int i = 0; i < numb; i++)
{
nodeinfo_23.Add(new List<int>());
lines_2.Add(new List<GameObject>());
nodenumrand = Random.Range(0, 4);
for (int j = 0; j < nodenumrand; j++)
{
nodenewrand = Random.Range(0, numb);
nodeinfo_23[i].Add(nodenewrand);
temp = drawline(Node_2[i].transform.position, Node_3[nodenewrand].transform.position,0);
lines_2[i].Add(temp);
}
}
//3rd node ~ answer
nodenumrand = Random.Range(1, 10);
for(int i=0; i<numb; i++)
lines_3.Add(new List<GameObject>());
for (int i=0; i<nodenumrand; i++)
{
nodenewrand = Random.Range(0, numb);
temp = drawline(Node_3[nodenewrand].transform.position, ansblock[targetnumb].transform.position,0);
lines_3[nodenewrand].Add(temp);
}
}
//섹션으로 해보기
void section_node()
{
Renderer Nodecolor;
GameObject temp;
int sec_1, sec_2;
int count = 0;
sec_1 = Random.Range(0,2);
sec_2 = Random.Range(0, 2);
for(int i=0; i<numb; i++)
{
Nodecolor = Node_1[i].GetComponent<Renderer>();
if (Nodecolor.material.color == Color.white)
{
for (int k = 0; k < nodeinfo_12[i].Count; k++)
{
if (((3.8 + 2.7 * sec_1 < Node_2[nodeinfo_12[i][k]].transform.position.z) && (3.8 + 2.7 * (sec_1 + 1) > Node_2[nodeinfo_12[i][k]].transform.position.z)) && (((-1.5 + 1.5 * sec_2 < Node_2[nodeinfo_12[i][k]].transform.position.y) && (-1.5 + 1.5 * (sec_2 + 1) > Node_2[nodeinfo_12[i][k]].transform.position.y))))
{
changeOBcolor(Node_2[nodeinfo_12[i][k]], 0);
for (int a = lines_1[i].Count - 1; a >= 0; a--)
Destroy(lines_1[i][a]);
temp = drawline(Node_1[i].transform.position, Node_2[nodeinfo_12[i][k]].transform.position, 1);
lines_1[i].Add(temp);
count++;
}
}
}
}
sec_1 = Random.Range(0, 2);
sec_2 = Random.Range(0, 2);
count = 0;
for (int i = 0; i < numb; i++)
{
Nodecolor = Node_2[i].GetComponent<Renderer>();
if (Nodecolor.material.color == Color.white)
{
for (int k = 0; k < nodeinfo_23[i].Count; k++)
{
if (((3.8 + 2.7 * sec_1 < Node_3[nodeinfo_23[i][k]].transform.position.z) && (3.8 + 2.7 * (sec_1 + 1) > Node_3[nodeinfo_23[i][k]].transform.position.z)) && (((-1.5 + 1.5 * sec_2 < Node_3[nodeinfo_23[i][k]].transform.position.y) && (-1.5 + 1.5 * (sec_2 + 1) > Node_3[nodeinfo_23[i][k]].transform.position.y))))
{
changeOBcolor(Node_3[nodeinfo_23[i][k]], 0);
for (int a = lines_2[i].Count - 1; a >= 0; a--)
Destroy(lines_2[i][a]);
temp = drawline(Node_2[i].transform.position, Node_3[nodeinfo_23[i][k]].transform.position, 1);
lines_2[i].Add(temp);
count++;
}
}
}
}
}
// 연결된 시냅스에서 신호의 전파
void change_node()
{
Renderer Nodecolor;
for(int i=0; i<numb; i++)
{
Nodecolor = Node_1[i].GetComponent<Renderer>();
if (Nodecolor.material.color == Color.white)
{
for(int j=0; j<numb; j++)
{
for(int k=0; k<nodeinfo_12[j].Count; k++)
{
if (Vector3.Distance(new Vector3(Node_1[i].transform.position.x, Node_1[i].transform.position.y, Node_1[i].transform.position.z), new Vector3(Node_1[i].transform.position.x + .2f, Node_2[nodeinfo_12[j][k]].transform.position.y, Node_2[nodeinfo_12[j][k]].transform.position.z)) < 1f)
{
changeOBcolor(Node_2[nodeinfo_12[j][k]], 0);
for(int a=0; a<lines_1[i].Count; a++)
{
changeLINEcolor(lines_1[i][a], 0);
}
}
}
}
}
}
}
void changeOBcolor(GameObject target, int colorcode)
{
Renderer Nodecolor = target.GetComponent<Renderer>();
//White
if (colorcode == 0)
{
Nodecolor.material.color = Color.white;
}
}
void changeLINEcolor(GameObject target, int colorcode)
{
Debug.Log("changeLINEcolor 실행");
LineRenderer linecolor = target.GetComponent<LineRenderer>();
//White
if (colorcode == 1)
{
linecolor.startColor = Color.cyan;
linecolor.endColor = Color.cyan;
}
}
void NodetoWhite(GameObject target)
{
Renderer Nodecolor = target.GetComponent<Renderer>();
Nodecolor.material.color = Color.white;
}
GameObject drawline(Vector3 start, Vector3 end, int colorcode)
{
GameObject liner = Instantiate(Line, new Vector3((start.x + end.x) / 2, (start.y + end.y) / 2, (start.z + end.z) / 2), Quaternion.identity);
lineRenderer = liner.GetComponent<LineRenderer>();
lineRenderer.SetPosition(0, start);
lineRenderer.SetWidth(.006f, .006f);
lineRenderer.SetPosition(1, end);
if(colorcode==0)
{
lineRenderer.startColor = Color.white;
lineRenderer.endColor = Color.white;
}
else if (colorcode == 1)
{
lineRenderer.startColor = Color.cyan;
lineRenderer.endColor = Color.cyan;
}
return liner;
}
void drawplane()
{
targetnumb = Random.Range(0, 10);
GameObject _obj_3;
for (int row = 0; row < 10; row++)
{
for (int col = 0; col < 10; col++)
{
if (numData[targetnumb][99 - (10 * row + col)] == 0)
{
_obj_3 = Instantiate(BBlock, new Vector3(-2f, 0.4f * row - 2.0f, 0.4f * col + 4.5f), Quaternion.identity);
}
else
{
_obj_3 = Instantiate(WBlock, new Vector3(-2f, 0.4f * row - 2.0f, 0.4f * col + 4.5f), Quaternion.identity);
}
BlockList.Add(_obj_3);
}
}
}
}
댓글
댓글 쓰기