private IEnumerator CoroutineSpawnDespawnChildren(float interval) { while (true) { ItemData[] list = itemTree.GetNearby(Camera.main.transform.position, visibleDistance); foreach (KeyValuePair <string, ItemData> kv in itemDictionary) { ItemData item = kv.Value; Transform childTransform = transform.Find(item.Key); bool isNearby = list.Contains(item); if (isNearby && childTransform == null) { CreateChild(item); } else if (isNearby && childTransform != null) { SetChild(item); } else { RemoveChild(item); } } yield return(new WaitForSeconds(interval)); } }
//get markers public bool GetMarkers(Vector3 head, ref Vector3 A, ref Vector3 B) { WatchData [] markers = pointTree.GetNearby(new Vector3(head.x, head.y, head.z), 1); //4 meters around head if (markers.Length > 0) { A = markers[0].position; B = markers[0].position; return(true); } return(false); }
void postRender(Camera cam) { List <PCLPoint> bodyPoints = KinectPCL.instance.bodyPoints; PointOctree <PCLPoint> po = KinectPCL.instance.bodyTree; if (po.Count == 0 || po.Count == KinectPCL.instance.numPoints) { return; } if (!processLines) { return; } GL.Begin(GL.LINES); lineMat.SetPass(0); foreach (PCLPoint p in bodyPoints) { Ray r = new Ray(p.position, Vector3.forward); PCLPoint[] np = po.GetNearby(r, maxDistance); foreach (PCLPoint npp in np) { if (npp.position.x < p.position.x || Vector3.Distance(npp.position, p.position) > maxDistance) { continue; } if (drawLines) { float dist = Vector3.Distance(npp.position, p.position); float targetAlpha = alphaDecay.Evaluate(dist / maxDistance); GL.Color(Color.Lerp(nearColor, farColor, targetAlpha)); GL.TexCoord(new Vector3(Time.time * targetAlpha, 0, 0)); GL.Vertex(npp.position); GL.TexCoord(new Vector3(Time.time * targetAlpha + 1, 0, 0)); GL.Vertex(p.position); } } } GL.End(); }
public static void GetCsvData(this StopLine stopLine, PointOctree <CsvLane> finalLanes, out List <CsvPoint> csvPoints, out List <CsvLine> csvLines, out List <CsvVector> csvVectors, out List <CsvSignalLight> csvSignalLights, out List <CsvStopLine> csvStopLines) { csvPoints = new List <CsvPoint>(); csvLines = new List <CsvLine>(); csvStopLines = new List <CsvStopLine>(); var csvSLPoints = new List <CsvPoint>(); csvVectors = new List <CsvVector>(); csvSignalLights = new List <CsvSignalLight>(); for (int i = 0; i < stopLine.Count; i++) { var csvPoint = new CsvPoint() { Position = stopLine.LineRenderer.GetPosition(i) }; csvPoints.Add(csvPoint); if (i > 0) { var csvLine = new CsvLine() { PointBegin = csvPoints[i - 1], PointFinal = csvPoint }; if (i > 1) { csvLine.LineLast = csvLines.Last(); } csvLines.Add(csvLine); var signalLight = stopLine.signalLights[i - 1]; var csvSLPoint = new CsvPoint() { Position = signalLight.transform.position }; csvSLPoints.Add(csvSLPoint); var csvVector = new CsvVector() { Point = csvSLPoint, Rotation = signalLight.transform.rotation }; csvVectors.Add(csvVector); var csvSignalLight = new CsvSignalLight() { Vector = csvVector }; csvSignalLights.Add(csvSignalLight); var midPoint = (csvLine.PointBegin.Position + csvLine.PointFinal.Position) / 2; var csvStopLine = new CsvStopLine() { Line = csvLine, SignalLight = csvSignalLight, Lane = finalLanes .GetNearby(midPoint, Vector3.Distance(csvLine.PointBegin.Position, csvLine.PointFinal.Position)) ?.OrderBy(_ => Vector3.Distance(_.FinalNode.Point.Position, midPoint))? .FirstOrDefault() }; csvStopLines.Add(csvStopLine); } } csvPoints.AddRange(csvSLPoints); }
void postRender(Camera cam) { //if (cam != Camera.main) return; if (autoBodyOnly) { bodyOnly = KinectPCLK1.instance.bodyPoints.Count > 10; realBodyOnly = bodyOnly; } List <PCLPoint> tPoints = bodyOnly ? KinectPCLK1.instance.bodyPoints : KinectPCLK1.instance.roiPoints; PointOctree <PCLPoint> po = bodyOnly ? KinectPCLK1.instance.bodyTree : KinectPCLK1.instance.roiTree; if (po.Count == 0 || (bodyOnly && po.Count == KinectPCLK1.instance.numPoints)) { return; } if (!processLines) { return; } lineMat.SetPass(0); foreach (PCLPoint p in tPoints) { if (!p.isInROI) { continue; } Ray r = new Ray(p.position, Vector3.forward); PCLPoint[] np = po.GetNearby(r, maxDistance); foreach (PCLPoint npp in np) { if (npp.position.x < p.position.x || Vector3.Distance(npp.position, p.position) > maxDistance) { continue; } if (drawLines) { float dist = Vector3.Distance(npp.position, p.position); float targetAlpha = alphaDecay.Evaluate(dist / maxDistance); GL.Begin(GL.LINES); GL.Color(Color.Lerp(nearColor, farColor, targetAlpha)); GL.TexCoord(Vector3.zero); GL.TexCoord(new Vector3(Time.time * texSpeed * targetAlpha, 0, 0)); GL.Vertex(npp.position); GL.TexCoord(Vector3.one); GL.TexCoord(new Vector3(Time.time * texSpeed * targetAlpha + 1, 0, 0)); GL.Vertex(p.position); GL.End(); } } } // GL.End(); }
/// <summary> /// Runs current tracked object data through Octree. /// </summary> private TrackedObjectStates evaluateOctree(OctreeThreadParameters otp) { int alloc = WorldMonitor.Instance.AllocationSpace; updatePositions = new Vector3[alloc]; // otp.ObjectIDs.Count float[] thresholds = new float[alloc]; // otp.ObjectIDs.Count //for (int i = 0; i < otp.ObjectIDs.Count; i++) foreach (int id in otp.ObjectIDs) { KeyValuePair <float, Vector3> pos; if (!otp.Coordinates.TryGetValue(id, out pos)) { Debug.LogError("unknown object position request in octree eval"); } thresholds[id] = pos.Key; updatePositions[id] = pos.Value; PointOctree.Remove(id); PointOctree.Add(id, pos.Value); } List <int[]> enteringIDs = new List <int[]>(); List <int[]> leavingIDs = new List <int[]>(); List <int> parentIDLeavers = new List <int>(); List <int> parentIDEnterers = new List <int>(); int ind = 0; foreach (int id in otp.ObjectIDs) { List <int> validConflicts = new List <int>(); List <int> stayers = new List <int>(); int[] areaObjects = PointOctree.GetNearby(updatePositions[id], thresholds[id]); for (int j = 0; j < areaObjects.Length; j++) { string affiliateObj = WorldMonitor.Instance.TrackedObjectAffiliations[id]; string affiliateCompare = WorldMonitor.Instance.TrackedObjectAffiliations[areaObjects[j]]; /* * run conflict validity checks: if not the same object && not an object of the same class type && is a new conflict */ if (areaObjects[j] != id && !MasterList[id].Contains(areaObjects[j]) && string.Compare(affiliateObj, affiliateCompare) != 0) { if (!parentIDEnterers.Contains(id)) { parentIDEnterers.Add(id); } MasterList[id].Add(areaObjects[j]); // add conflicting object to master list of current conflicts validConflicts.Add(areaObjects[j]); // *new* conflicts stayers.Add(areaObjects[j]); // use to look for conflicts that have ended } else if (MasterList[id].Contains(areaObjects[j])) { stayers.Add(areaObjects[j]); // this is an object staying in conflict } } bool leaverDetected = false; List <int> leavers = new List <int>(); foreach (int _id in MasterList[id]) // look at master list's record of conflicts for this parent ID - if it isn't in stayers, it has left the conflict area or been destroyed { if (!stayers.Contains(_id)) { leaverDetected = true; leavers.Add(_id); } switch (WorldMonitor.Instance.ConflictEndMode) { case ConflictEndMode.OnAllConflictsEnded: if (leavers.Count == MasterList[id].Count) { parentIDLeavers.Add(id); } break; case ConflictEndMode.OnIndividualConflictEnded: if (leaverDetected && !parentIDEnterers.Contains(id) && !parentIDLeavers.Contains(id)) { parentIDLeavers.Add(id); } break; } } foreach (int leaver in leavers) { MasterList[id].Remove(leaver); } int numValid = leavers.ToArray().Length; if (numValid > 0) { leavingIDs.Add(leavers.ToArray()); } numValid = validConflicts.ToArray().Length; if (numValid > 0) { enteringIDs.Add(validConflicts.ToArray()); } ind++; } return(new TrackedObjectStates { ParentIDEnterers = parentIDEnterers.ToArray(), // parent IDs of new or increased conflict states ParentIDLeavers = parentIDLeavers.ToArray(), // parent IDs of expired or reduced conflict states LeavingIDs = leavingIDs, // child IDs - ended conflict(s) EnteringIDs = enteringIDs, // child IDs - the conflict(s) PriorConflictingIDs = parentIDLeavers // parent IDs that need informed all conflicts have ceased }); }