private void iterateOverCone(int n, ref vertexData a, ref vertexData b, ref vertexData c) { float alpha, scaler_i, length; Color auxColor = ColorOfCone; vertexData cprime, bprime; Vector2 biv, civ; for (int i = 0; i < n; i++) { scaler_i = (float)i / n; alpha = i / (float)auxrad; cprime = c * scaler_i; civ = cprime.Iv = Vector2.Lerp(a.Iv, c.Iv, scaler_i); bprime = b * scaler_i; biv = bprime.Iv = Vector2.Lerp(a.Iv, b.Iv, scaler_i); vertexData bprime_cprime = cprime - bprime; length = bprime_cprime.length / dimensionsOfQuad * dimensionsOfTexture; for (int j = 0; j < length; j++) { float scaler_j = j / length; //Vector2 pixelOFTexture = (civ - biv).normalized * scaler_j * dimensionsOfTexture; Vector2 pixelOfTexture = Vector2.Lerp(biv, civ, scaler_j) * dimensionsOfTexture; pixelsColored.Add(pixelOfTexture); auxColor.a = 1 - alpha; fogOfWarText.SetPixel((int)(pixelOfTexture.x), (int)(pixelOfTexture.y), (ColorOfCone * (1 - alpha) + ColorOfPath * alpha)); } } }
// Update is called once per frame void Update() { Vector3 sourcePos = sourceOfCone.transform.position; auxrad = Radius * sampleModifier; vertexData a = new vertexData(sourcePos, getIvsat(sourcePos)); for (int i = 0; i < pixelsColored.Count; i++) { fogOfWarText.SetPixel((int)(pixelsColored[i].x), (int)(pixelsColored[i].y), ColorOfPath); } pixelsColored.Clear(); for (int i = 0; i < CollisionPoints.Count - 1; i++) { Vector3 tempb = CollisionPoints[i], tempc = CollisionPoints[i + 1]; float distab = Vector2.Distance(sourcePos, tempb); float distac = Vector2.Distance(sourcePos, tempc); vertexData[] data = getBCData(tempb, tempc); vertexData b = data[0]; vertexData c = data[1]; float tempDist = (distab > distac ? distab : distac); float n = tempDist / dimensionsOfQuad * dimensionsOfTexture * sampleModifier; iterateOverCone((int)n, ref a, ref b, ref c); } fogOfWarText.Apply(); }
private vertexData[] getBCData(Vector3 b, Vector3 c) { vertexData bdata = new vertexData(b, getIvsat(b)); vertexData cdata = new vertexData(c, getIvsat(c)); vertexData[] data = { bdata, cdata }; return(data); }
public IEnumerator exportBaseGraphData() { yield return(new WaitForSeconds(1)); baseGraphData baseGraph = new baseGraphData(); baseGraph.size = this.size; GameObject[] vertexGOs = new GameObject[transform.childCount]; //vertexGOs = GameObject.FindGameObjectsWithTag("vertex"); for (int i = 0; i < transform.childCount; i++) { vertexGOs[i] = transform.GetChild(i).gameObject; } foreach (GameObject vertex in vertexGOs) { vertexData vertexData = new vertexData(); vertexScript vs = vertex.GetComponent <vertexScript>(); GameObject[] edgeGOs = new GameObject[vertex.transform.childCount]; //Debug.Log("This vertex has " + vertex.transform.childCount + " children"); for (int i = 0; i < vertex.transform.childCount; i++) { edgeGOs[i] = vertex.transform.GetChild(i).gameObject; } bool[] activeEdges = new bool[8]; for (int j = 0; j < edgeGOs.Length - 1; j++) { //Debug.Log("J - " + j + ", edgesGOs Length - " + edgeGOs.Length); if (edgeGOs[j].GetComponent <MeshRenderer>().enabled == true) { if (vs.isEdgeConnected(edgeGOs[j].GetComponent <edgeScript>()) != -1) { activeEdges[vs.isEdgeConnected(edgeGOs[j].GetComponent <edgeScript>())] = true; } } } vertexData.setVertexData(vs.getPos(), activeEdges, vs.getStartingPoint(), vs.getObjectivePoint()); baseGraph.addVertex(vertexData); } string baseGraphString = JsonUtility.ToJson(baseGraph); DirectoryInfo dir = new DirectoryInfo("Assets/baseGraphJSONs/"); FileInfo[] fileInfo = dir.GetFiles(); System.IO.File.WriteAllText("Assets/baseGraphJSONs/BaseGraphData" + fileInfo.Count() + ".json", baseGraphString); baseGraphString = ""; baseGraph.clear(); }
IEnumerator dataPassing() { while (true) { for (int x = 1; x < net_visualizer.GetLength(0); x++) { float height = startPoints[x].position.y; vertexData lastData = new vertexData(); for (int y = 0; y < net_visualizer.GetLength(1); y++) { //vertexData pointData = new vertexData(); if (y == 0) { // Vector3 point = new Vector3( // startPoints[x].position.x, // startPoints[x].position.y, // startPoints[x].position.z); Vector3 towardVecotor = startPoints[x].position - centerObject.transform.position; net_visualizer[x, y].height = startPoints[x].position.y; towardVecotor.y = 0; net_visualizer[x, y].radius = towardVecotor.magnitude; lastData = net_visualizer[x, y]; } else { vertexData _pointData = new vertexData(); _pointData = net_visualizer[x, y]; net_visualizer[x, y].height = lastData.height; net_visualizer[x, y].radius = lastData.radius; float degree = (360 / horizontalDataNumber) * y; if (degree > displayAngle) { continue; } degree *= Mathf.Deg2Rad; lastData.position.y = 0; Vector3 pos = Quaternion.AngleAxis(-360 / horizontalDataNumber, Vector3.up) * lastData.position; pos = pos.normalized * net_visualizer[x, y].radius; pos.y = net_visualizer[x, y].height; net_visualizer[x, y].position = pos; lastData = _pointData; } } } yield return(new WaitForSeconds(compute_Interval * 1 / speed)); } }
internal void BGEOLODConstructor(GEOM[] lodMorphMeshes, int indexIn, out int firstVertID, out Section2[] outSection2, out Section3[] outSection3, out int indexOut) { float posLimit = 0f; float normLimit = 0f; int lowVertID = Int32.MaxValue; int hiVertID = 0; for (int seq = 0; seq < lodMorphMeshes.Length; seq++) { if (!lodMorphMeshes[seq].isMorph) { throw new BlendException("Not a valid morph mesh!"); } lowVertID = Math.Min(lodMorphMeshes[seq].minVertexID, lowVertID); hiVertID = Math.Max(lodMorphMeshes[seq].maxVertexID, hiVertID); } bool overlap = false; if ((lodMorphMeshes.Length > 1) && ((lodMorphMeshes[1].minVertexID > lodMorphMeshes[0].minVertexID & lodMorphMeshes[1].minVertexID < lodMorphMeshes[0].maxVertexID) | (lodMorphMeshes[1].maxVertexID > lodMorphMeshes[0].minVertexID & lodMorphMeshes[1].maxVertexID < lodMorphMeshes[0].maxVertexID))) { overlap = true; } if ((lodMorphMeshes.Length > 2) && ((lodMorphMeshes[2].minVertexID > lodMorphMeshes[0].minVertexID & lodMorphMeshes[2].minVertexID < lodMorphMeshes[0].maxVertexID) | (lodMorphMeshes[2].maxVertexID > lodMorphMeshes[0].minVertexID & lodMorphMeshes[2].maxVertexID < lodMorphMeshes[0].maxVertexID))) { overlap = true; } if ((lodMorphMeshes.Length > 2) && ((lodMorphMeshes[2].minVertexID > lodMorphMeshes[1].minVertexID & lodMorphMeshes[2].minVertexID < lodMorphMeshes[1].maxVertexID) | (lodMorphMeshes[2].maxVertexID > lodMorphMeshes[1].minVertexID & lodMorphMeshes[2].maxVertexID < lodMorphMeshes[1].maxVertexID))) { overlap = true; } if (overlap) { if (MessageBox.Show("Your meshes have overlapping vertex IDs within\na LOD and the morph may not work correctly.\nDo you want to continue anyway?", "Vertex numbering alert", MessageBoxButtons.YesNo) == DialogResult.No) { throw new BlendException("Vertex numbering error"); } } int numVertIDs = hiVertID - lowVertID + 1; vertexData[] vertList = new vertexData[numVertIDs]; for (int seq = 0; seq < lodMorphMeshes.Length; seq++) { for (int i = 0; i < lodMorphMeshes[seq].numberVertices; i++) { int ID = lodMorphMeshes[seq].getVertexID(i); vertList[ID - lowVertID] = new vertexData(ID, lodMorphMeshes[seq].getPosition(i), lodMorphMeshes[seq].getNormal(i)); } } bool gap = false; float[] nothing = new float[3]; for (int i = 0; i < vertList.Length; i++) { if (vertList[i] == null) { gap = true; vertList[i] = new vertexData(i + lowVertID, nothing, nothing); } } if (gap) { if (MessageBox.Show("Your meshes have a gap in vertex IDs within\na LOD but the morph will probably work.\nDo you want to continue anyway?", "Vertex numbering alert", MessageBoxButtons.YesNo) == DialogResult.No) { throw new BlendException("Vertex numbering error"); } } Section2[] newSect2 = new Section2[numVertIDs]; List <Section3> listSect3 = new List <Section3>(); int offset = 0 - indexIn; for (int i = 0; i < vertList.Length; i++) { bool hasPos = false; bool hasNorm = false; if (Math.Abs(vertList[i].posX) > posLimit | Math.Abs(vertList[i].posY) > posLimit | Math.Abs(vertList[i].posZ) > posLimit) { listSect3.Add(new Section3(vertList[i].posX, vertList[i].posY, vertList[i].posZ)); hasPos = true; } if (Math.Abs(vertList[i].normX) > normLimit | Math.Abs(vertList[i].normY) > normLimit | Math.Abs(vertList[i].normZ) > normLimit) { listSect3.Add(new Section3(vertList[i].normX, vertList[i].normY, vertList[i].normZ)); hasNorm = true; } if (hasPos | hasNorm) { newSect2[i] = new Section2(hasPos, hasNorm, offset); offset = 0; if (hasPos) { offset++; } if (hasNorm) { offset++; } } else { newSect2[i] = new Section2(false, false, 0); } } firstVertID = lowVertID; outSection2 = newSect2; outSection3 = listSect3.ToArray(); indexOut = outSection3.Length - offset; }
public void addVertex(vertexData v) { vertices.Add(v); }
private void Start() { if (centerObject == null) { GameObject center = GameObject.CreatePrimitive(PrimitiveType.Sphere); center.name = "Center"; center.transform.parent = this.transform; center.transform.eulerAngles = Vector3.down * 180; center.transform.localPosition = Vector3.forward * 6; } if (startPoints.Length == 0 && StartPointParentObject == null) { GameObject StartPoint = GameObject.CreatePrimitive(PrimitiveType.Sphere); StartPoint.name = "StartPoint"; StartPoint.transform.parent = this.transform; StartPoint.transform.localPosition = Vector3.zero; GameObject StartPoint_1 = GameObject.CreatePrimitive(PrimitiveType.Sphere); StartPoint_1.name = "StartPoint_1"; StartPoint_1.transform.parent = StartPoint.transform; StartPoint_1.transform.localPosition = Vector3.left * 6; } else if (StartPointParentObject != null && !isUseCustomData) { startPoints = StartPointParentObject.transform.GetComponentsInChildren <Transform>(); } net_visualizer = new vertexData[startPoints.Length, horizontalDataNumber]; //ignore x = 0, because it will get parent transform for (int x = 1; x < net_visualizer.GetLength(0); x++) { float height = startPoints[x].position.y; for (int y = 0; y < net_visualizer.GetLength(1); y++) { vertexData pointData = new vertexData(); if (y == 0) { Vector3 point = pointData.position = new Vector3( startPoints[x].position.x, startPoints[x].position.y, startPoints[x].position.z); Vector3 towardVecotor = centerObject.transform.position - point; pointData.height = height = point.y; towardVecotor.y = 0; pointData.radius = towardVecotor.magnitude; } else { pointData.height = net_visualizer[x, y - 1].height; pointData.radius = net_visualizer[x, y - 1].radius; float degree = (360 / horizontalDataNumber) * y; if (degree > displayAngle) { continue; } degree *= Mathf.Deg2Rad; Vector3 pos = Quaternion.AngleAxis(-360 / horizontalDataNumber, Vector3.up) * net_visualizer[x, y - 1].position; pointData.position = pos; } net_visualizer[x, y] = pointData; } } StartCoroutine(dataPassing()); }