/// <summary> /// Finds all the neighbour nodes of a mid Node /// </summary> /// <param name="mid">Mid Node</param> /// <returns>Returns a list of neighbour nodes</returns> public List <Node> FindNeighbourMidNodes(MidNode mid) { //Half of the section length float halfLength = Mathf.Floor(sectionLength * matrixSize / 2); //Actual length float length = sectionLength; //the vector3 input Vector3 input = mid.vertexPosition; //Every node has a fixed amount of starting nodes - 8. Four vertices on top and four on the bottom. List <Node> tempNodes = new List <Node>() { new Node(new Vector3(input.x - halfLength - positionOffest.x, input.y + halfLength - positionOffest.y, input.z - halfLength - positionOffest.z)), new Node(new Vector3(input.x - halfLength - positionOffest.x, input.y + halfLength - positionOffest.y, input.z + halfLength - positionOffest.z)), new Node(new Vector3(input.x + halfLength - positionOffest.x, input.y + halfLength - positionOffest.y, input.z - halfLength - positionOffest.z)), new Node(new Vector3(input.x + halfLength - positionOffest.x, input.y + halfLength - positionOffest.y, input.z + halfLength - positionOffest.z)), new Node(new Vector3(input.x - halfLength - positionOffest.x, input.y - halfLength - positionOffest.y, input.z - halfLength - positionOffest.z)), new Node(new Vector3(input.x - halfLength - positionOffest.x, input.y - halfLength - positionOffest.y, input.z + halfLength - positionOffest.z)), new Node(new Vector3(input.x + halfLength - positionOffest.x, input.y - halfLength - positionOffest.y, input.z - halfLength - positionOffest.z)), new Node(new Vector3(input.x + halfLength - positionOffest.x, input.y - halfLength - positionOffest.y, input.z + halfLength - positionOffest.z)), }; //For each element different than null in the list, add the midnode to it - The tempnode are the midnode neighbours, this code makes the back relation tempNodes.Where(t => t != null).ToList().ForEach(x => { List <Node> ne = FindNeighbourNodes(x.vertexPosition); GameObject p = GameObject.CreatePrimitive(PrimitiveType.Cube); p.transform.position = x.vertexPosition; x.neighbourNodes.Clear(); x.neighbourNodes = ne; x.neighbourNodes.Add(mid); }); return(tempNodes.Where(t => t != null).ToList()); }
public bool SaveMNode([FromUri] MidNode node) { MongoHelper <MidNode> helperNode = new MongoHelper <MidNode>(dbName); if (string.IsNullOrEmpty(node.id_string)) { //node.id = ObjectId.Empty; node.delflag = 0; node.identify = null; node.regcode = null; node.identify = DateTime.Now.Ticks.ToString();//新增的时候生成标识码 node.createdate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); helperNode.Insert(node); } else { MidNode _node = helperNode.Find(node.id_string); _node.nodename = node.nodename; _node.machinecode = node.machinecode; _node.memo = node.memo; _node.regcode = node.regcode; //_node.identify = node.identify; helperNode.Update(_node); } return(true); }
public bool OnOffMidNode(string id) { MongoHelper <MidNode> helperNode = new MongoHelper <MidNode>(dbName); MidNode node = helperNode.Find(id); helperNode.Update(id, "delflag", node.delflag == 0 ? 1 : 0); return(true); }
/// <summary> /// Creates the actual matrix /// </summary> public void CreateMatrix() { //Clear the lists of position - Debugging - nodes and midpoints. positions.Clear(); nodes.Clear(); midNodes.Clear(); //loops matrix for (int i = 0; i < matrix.Length; i += sectionLength) { for (int j = 0; j < matrix.Length; j += sectionLength) { for (int k = 0; k < matrix.Length; k += sectionLength) { //This node's iteration position var nodePos = new Vector3(i - positionOffest.x, j - positionOffest.y, k - positionOffest.z) * matrixSize; var lineLength = matrixSize * sectionLength; var oppositeVertex = Vector3.zero; //Checks if the section determined from this node position to the next node is contained withing the boundaries of the matrix if (i + sectionLength < matrix.Length && j + sectionLength < matrix.Length && k + sectionLength < matrix.Length) { oppositeVertex = new Vector3(i + sectionLength - positionOffest.x, j + sectionLength - positionOffest.y, k + sectionLength - positionOffest.z) * matrixSize; var diag1 = new Vector3(oppositeVertex.x - sectionLength * matrixSize, oppositeVertex.y, oppositeVertex.z); var diag2 = new Vector3(nodePos.x + sectionLength * matrixSize, nodePos.y, nodePos.z); var midPos = (diag1 + diag2) / 2; //Creates a midnode object MidNode mid = new MidNode(midPos); var tem = FindNeighbourMidNodes(mid); //Inicializes the object's neighbour nodes mid.neighbourNodes = tem; //Adds it to the list midNodes.Add(mid); } //Gets the neighbour nodes of this iteration's node List <Node> tempNodes = new List <Node>(); tempNodes = FindNeighbourNodes(nodePos); //Creates the actual node and adds it to the list of nodes Node posNode = new Node(nodePos, oppositeVertex, tempNodes.Where(q => q != null).ToList()); nodes.Add(posNode); } } } }