void Awake() { pointArr = new LidarPointArray(); pointArr.Init(360 / degPerSweepInc * numSweepsLevels); int v = 0; foreach (string layerName in layerMaskNames) { int layer = LayerMask.NameToLayer(layerName); v |= 1 << layer; } collMask |= ~v; }
public void SetConfig(float offset_x, float offset_y, float offset_z, float rot_x, int _degPerSweepInc, float _degAngDown, float _degAngDelta, float _maxRange, float _noise, int _numSweepsLevels) { degPerSweepInc = _degPerSweepInc; degAngDown = _degAngDown; degAngDelta = _degAngDelta; maxRange = _maxRange; noise = _noise; numSweepsLevels = _numSweepsLevels; if (offset_x != 0.0f || offset_y != 0.0f || offset_z != 0.0f) { transform.localPosition = new Vector3(offset_x, offset_y, offset_z); } if (rot_x != 0.0f) { transform.localEulerAngles = new Vector3(rot_x, 0.0f, 0.0f); } pointArr = new LidarPointArray(); pointArr.Init(360 / degPerSweepInc * numSweepsLevels); }
public LidarPointArray GetOutput() { pointArr = new LidarPointArray(); pointArr.Init(360 / degPerSweepInc * numSweepsLevels); pointArr.lidarPos = new V3(transform.position); pointArr.lidarOrientation = new V3(transform.rotation.eulerAngles); Ray ray = new Ray(); ray.origin = this.transform.position; ray.direction = this.transform.forward; //start out pointing a bit down. Quaternion rotDown = Quaternion.AngleAxis(degAngDown, transform.right); ray.direction = rotDown * ray.direction; int numSweep = 360 / degPerSweepInc; Quaternion rotSide = Quaternion.AngleAxis(degPerSweepInc, transform.up); Quaternion rotUp = Quaternion.AngleAxis(degAngDelta, transform.right); RaycastHit hit; //Sample the output texture to create rays. int iP = 0; float rx = 0.0f; float ry = 0.0f; for (int iS = 0; iS < numSweepsLevels; iS++) { for (int iA = 0; iA < numSweep; iA++) { if (Physics.Raycast(ray, out hit, maxRange, collMask)) { //sample that ray at the depth given by the pixel. Vector3 pos = ray.GetPoint(hit.distance); //make points relative to my pos. pos = pos - transform.position; //shouldn't hit this unless user is messing around in the interface with things running. if (iP >= pointArr.points.Length) { break; } float noiseX = Mathf.PerlinNoise(UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f)); float noiseY = Mathf.PerlinNoise(UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f)); float noiseZ = Mathf.PerlinNoise(UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f)); pos.x += noise * noiseX; pos.y += noise * noiseY; pos.z += noise * noiseZ; //set iPoint pointArr.points[iP] = new LidarPoint(pos, rx, ry); ray.direction = rotSide * ray.direction; iP++; } rx += degPerSweepInc; } ray.direction = rotUp * ray.direction; ry += degAngDelta; rx = 0.0f; } return(pointArr); }
public LidarPointArray GetOutput() { int numSweep = (int)(360 / degPerSweepInc); pointArr = new LidarPointArray(); pointArr.Init(numSweep * numSweepsLevels); Ray ray = new Ray(transform.position, transform.forward); RaycastHit hit; // Vertical rotation Quaternion rotUp = Quaternion.AngleAxis(degAngDelta, transform.right); // Horizontal rotation Quaternion rotSide = Quaternion.AngleAxis(degPerSweepInc, transform.up); //Sample the output texture to create rays. int iP = 0; float rx = 0.0f; float ry = 0.0f; for (int iS = 0; iS < numSweepsLevels; iS++) { // reset the orientation of the ray Quaternion rotDown = Quaternion.AngleAxis(degAngDown + iS * degAngDelta, transform.right); ray.direction = rotDown * transform.forward; rx = 0.0f; for (int iA = 0; iA < numSweep; iA++) { if (Physics.Raycast(ray, out hit, maxRange, collMask)) { //sample that ray at the depth given by the pixel. Vector3 pos = hit.point - transform.position; float distance = hit.distance; //shouldn't hit this unless user is messing around in the interface with things running. if (iP >= pointArr.points.Length) { break; } // add some noise to the point position float noiseX = Mathf.PerlinNoise(UnityEngine.Random.Range(-1f, 1f), UnityEngine.Random.Range(-1f, 1f)); float noiseY = Mathf.PerlinNoise(UnityEngine.Random.Range(-1f, 1f), UnityEngine.Random.Range(-1f, 1f)); float noiseZ = Mathf.PerlinNoise(UnityEngine.Random.Range(-1f, 1f), UnityEngine.Random.Range(-1f, 1f)); pos.x += noise * noiseX; pos.y += noise * noiseY; pos.z += noise * noiseZ; //set iPoint pointArr.points[iP] = new LidarPoint(pos, distance, rx, ry); iP++; } ray.direction = rotSide * ray.direction; rx += degPerSweepInc; } ray.direction = rotUp * ray.direction; ry += degAngDelta; } return(pointArr); }
void Awake() { pointArr = new LidarPointArray(); pointArr.Init(360 / degPerSweepInc * numSweepsLevels); }