private static void UpdateBeam(ref LaserBeam.FrameData frame, LaserBeam beam) { Vector3 vector; Transform transform = beam.transform; frame.origin = transform.position; frame.direction = transform.forward; frame.direction.Normalize(); int beamLayers = (int)beam.beamLayers; if (beamLayers == 0) { frame.hit = false; } else if (beam.isViewModel) { RaycastHit2 hit; if (frame.hit = Physics2.Raycast2(frame.origin, frame.direction, out hit, beam.beamMaxDistance, beamLayers)) { frame.hitPoint = hit.point; frame.hitNormal = hit.normal; } } else { RaycastHit hit2; if (frame.hit = Physics.Raycast(frame.origin, frame.direction, out hit2, beam.beamMaxDistance, beamLayers)) { frame.hitPoint = hit2.point; frame.hitNormal = hit2.normal; } } if (!frame.hit) { frame.didHit = false; frame.point.x = frame.origin.x + (frame.direction.x * beam.beamMaxDistance); frame.point.y = frame.origin.y + (frame.direction.y * beam.beamMaxDistance); frame.point.z = frame.origin.z + (frame.direction.z * beam.beamMaxDistance); frame.distance = beam.beamMaxDistance; frame.distanceFraction = 1f; frame.pointWidth = beam.beamWidthEnd; } else { frame.point = frame.hitPoint; frame.didHit = true; frame.distance = (((frame.direction.x * frame.point.x) + (frame.direction.y * frame.point.y)) + (frame.direction.z * frame.point.z)) - (((frame.direction.x * frame.origin.x) + (frame.direction.y * frame.origin.y)) + (frame.direction.z * frame.origin.z)); frame.distanceFraction = frame.distance / beam.beamMaxDistance; frame.pointWidth = Mathf.Lerp(beam.beamWidthStart, beam.beamWidthEnd, frame.distanceFraction); frame.dotRadius = Mathf.Lerp(beam.dotRadiusStart, beam.dotRadiusEnd, frame.distanceFraction); } frame.originWidth = beam.beamWidthStart; vector.x = vector.y = vector.z = frame.originWidth; frame.bounds = new Bounds(frame.origin, vector); vector.x = vector.y = vector.z = frame.pointWidth; frame.bounds.Encapsulate(new Bounds(frame.point, vector)); frame.beamsLayer = ((int)1) << beam.gameObject.layer; allBeamsMask |= frame.beamsLayer; }
private static void UpdateBeam(ref LaserBeam.FrameData frame, LaserBeam beam) { RaycastHit2 raycastHit2; RaycastHit raycastHit; Vector3 vector3 = new Vector3(); bool flag; Transform transforms = beam.transform; frame.origin = transforms.position; frame.direction = transforms.forward; frame.direction.Normalize(); int num = beam.beamLayers; if (num == 0) { frame.hit = false; } else if (!beam.isViewModel) { bool flag1 = Physics.Raycast(frame.origin, frame.direction, out raycastHit, beam.beamMaxDistance, num); flag = flag1; frame.hit = flag1; if (flag) { frame.hitPoint = raycastHit.point; frame.hitNormal = raycastHit.normal; } } else { bool flag2 = Physics2.Raycast2(frame.origin, frame.direction, out raycastHit2, beam.beamMaxDistance, num); flag = flag2; frame.hit = flag2; if (flag) { frame.hitPoint = raycastHit2.point; frame.hitNormal = raycastHit2.normal; } } if (frame.hit) { frame.point = frame.hitPoint; frame.didHit = true; frame.distance = frame.direction.x * frame.point.x + frame.direction.y * frame.point.y + frame.direction.z * frame.point.z - (frame.direction.x * frame.origin.x + frame.direction.y * frame.origin.y + frame.direction.z * frame.origin.z); frame.distanceFraction = frame.distance / beam.beamMaxDistance; frame.pointWidth = Mathf.Lerp(beam.beamWidthStart, beam.beamWidthEnd, frame.distanceFraction); frame.dotRadius = Mathf.Lerp(beam.dotRadiusStart, beam.dotRadiusEnd, frame.distanceFraction); } else { frame.didHit = false; frame.point.x = frame.origin.x + frame.direction.x * beam.beamMaxDistance; frame.point.y = frame.origin.y + frame.direction.y * beam.beamMaxDistance; frame.point.z = frame.origin.z + frame.direction.z * beam.beamMaxDistance; frame.distance = beam.beamMaxDistance; frame.distanceFraction = 1f; frame.pointWidth = beam.beamWidthEnd; } frame.originWidth = beam.beamWidthStart; float single = frame.originWidth; float single1 = single; vector3.z = single; float single2 = single1; single1 = single2; vector3.y = single2; vector3.x = single1; frame.bounds = new Bounds(frame.origin, vector3); float single3 = frame.pointWidth; single1 = single3; vector3.z = single3; float single4 = single1; single1 = single4; vector3.y = single4; vector3.x = single1; frame.bounds.Encapsulate(new Bounds(frame.point, vector3)); frame.beamsLayer = 1 << (beam.gameObject.layer & 31); LaserGraphics.allBeamsMask = LaserGraphics.allBeamsMask | frame.beamsLayer; }
private static void RenderBeam(Plane[] frustum, Camera camera, LaserBeam beam, ref LaserBeam.FrameData frame) { Vector3 upwards = world2Cam.MultiplyPoint(frame.origin); Vector3 vector2 = world2Cam.MultiplyPoint(frame.point); Vector3 forward = vector2 - upwards; forward.Normalize(); float num = 1f - ((1f - Mathf.Abs(forward.z)) * beam.beamOutput); Quaternion quaternion = Quaternion.LookRotation(forward, vector2); Vector3 vector4 = (Vector3)(Quaternion.LookRotation(forward, upwards) * new Vector3(frame.originWidth, 0f, 0f)); Vector3 vector5 = (Vector3)(quaternion * new Vector3(frame.pointWidth, 0f, 0f)); frame.beamVertices.m0 = cam2World.MultiplyPoint(((Vector3)(vector4 * 0.5f)) + upwards); frame.beamVertices.m2 = cam2World.MultiplyPoint(((Vector3)(vector5 * 0.5f)) + vector2); frame.beamVertices.m1 = cam2World.MultiplyPoint(((Vector3)(vector4 * -0.5f)) + upwards); frame.beamVertices.m3 = cam2World.MultiplyPoint(((Vector3)(vector5 * -0.5f)) + vector2); frame.beamNormals.m0.x = frame.originWidth; frame.beamNormals.m2.x = frame.pointWidth; frame.beamNormals.m1.x = -frame.originWidth; frame.beamNormals.m3.x = -frame.pointWidth; frame.beamNormals.m0.y = -frame.distance; frame.beamNormals.m1.y = -frame.distance; frame.beamNormals.m2.y = -frame.distance; frame.beamNormals.m3.y = -frame.distance; frame.beamNormals.m0.z = frame.beamNormals.m1.z = 0f; frame.beamNormals.m2.z = frame.beamNormals.m3.z = frame.distanceFraction; frame.beamColor.m0 = frame.beamColor.m1 = frame.beamColor.m2 = frame.beamColor.m3 = RangeBeamColor((Color)(beam.beamColor * num)); frame.beamUVs.m0 = uv[0]; frame.beamUVs.m0.x *= frame.distanceFraction; frame.beamUVs.m1 = uv[1]; frame.beamUVs.m1.x *= frame.distanceFraction; frame.beamUVs.m2 = uv[2]; frame.beamUVs.m2.x *= frame.distanceFraction; frame.beamUVs.m3 = uv[3]; frame.beamUVs.m3.x *= frame.distanceFraction; frame.bufBeam = MeshBuffer.ForBeamMaterial(beam.beamMaterial); if (Computation.beams.Add(frame.bufBeam)) { frame.bufBeam.measureSize = 1; } else { frame.bufBeam.measureSize++; } frame.bufBeam.beams.Add(beam); if (frame.didHit) { Vector3 vector6 = world2Cam.MultiplyVector(-frame.hitNormal); if (vector6.z < 0f) { Vector3 start = cam2World.MultiplyPoint(Vector3.zero); if (!Physics.Linecast(start, Vector3.Lerp(start, frame.point, 0.95f), (int)beam.cullLayers)) { Vector3 vector8 = world2Cam.MultiplyPoint(frame.point); Quaternion quaternion3 = Quaternion.LookRotation(vector8, Vector3.up); frame.dotVertices1.m0 = cam2World.MultiplyPoint(vector8 + (quaternion3 * new Vector3(frame.dotRadius, -frame.dotRadius, 0f))); frame.dotVertices1.m1 = cam2World.MultiplyPoint(vector8 + (quaternion3 * new Vector3(frame.dotRadius, frame.dotRadius, 0f))); frame.dotVertices1.m2 = cam2World.MultiplyPoint(vector8 + (quaternion3 * new Vector3(-frame.dotRadius, -frame.dotRadius, 0f))); frame.dotVertices1.m3 = cam2World.MultiplyPoint(vector8 + (quaternion3 * new Vector3(-frame.dotRadius, frame.dotRadius, 0f))); quaternion3 = Quaternion.LookRotation(vector6, Vector3.up); frame.dotVertices2.m0 = cam2World.MultiplyPoint(vector8 + (quaternion3 * new Vector3(frame.dotRadius, -frame.dotRadius, -0.01f))); frame.dotVertices2.m1 = cam2World.MultiplyPoint(vector8 + (quaternion3 * new Vector3(frame.dotRadius, frame.dotRadius, -0.01f))); frame.dotVertices2.m2 = cam2World.MultiplyPoint(vector8 + (quaternion3 * new Vector3(-frame.dotRadius, -frame.dotRadius, -0.01f))); frame.dotVertices2.m3 = cam2World.MultiplyPoint(vector8 + (quaternion3 * new Vector3(-frame.dotRadius, frame.dotRadius, -0.01f))); frame.dotColor1.m0 = frame.dotColor1.m1 = frame.dotColor1.m2 = frame.dotColor1.m3 = frame.dotColor2.m0 = frame.dotColor2.m1 = frame.dotColor2.m2 = frame.dotColor2.m3 = RangeDotColor(beam.dotColor); frame.bufDot = MeshBuffer.ForDotMaterial(beam.dotMaterial); if (Computation.dots.Add(frame.bufDot)) { frame.bufDot.measureSize = 2; } else { frame.bufDot.measureSize += 2; } frame.bufDot.beams.Add(beam); frame.drawDot = true; } else { frame.bufDot = null; frame.drawDot = false; } } else { frame.bufDot = null; frame.drawDot = false; } } else { frame.bufDot = null; frame.drawDot = false; } }
private static void RenderBeam(Plane[] frustum, Camera camera, LaserBeam beam, ref LaserBeam.FrameData frame) { Vector3 vector3 = LaserGraphics.world2Cam.MultiplyPoint(frame.origin); Vector3 vector31 = LaserGraphics.world2Cam.MultiplyPoint(frame.point); Vector3 vector32 = vector31 - vector3; vector32.Normalize(); float single = 1f - (1f - Mathf.Abs(vector32.z)) * beam.beamOutput; Quaternion quaternion = Quaternion.LookRotation(vector32, vector31); Quaternion quaternion1 = Quaternion.LookRotation(vector32, vector3); Vector3 vector33 = quaternion1 * new Vector3(frame.originWidth, 0f, 0f); Vector3 vector34 = quaternion * new Vector3(frame.pointWidth, 0f, 0f); frame.beamVertices.m0 = LaserGraphics.cam2World.MultiplyPoint((vector33 * 0.5f) + vector3); frame.beamVertices.m2 = LaserGraphics.cam2World.MultiplyPoint((vector34 * 0.5f) + vector31); frame.beamVertices.m1 = LaserGraphics.cam2World.MultiplyPoint((vector33 * -0.5f) + vector3); frame.beamVertices.m3 = LaserGraphics.cam2World.MultiplyPoint((vector34 * -0.5f) + vector31); frame.beamNormals.m0.x = frame.originWidth; frame.beamNormals.m2.x = frame.pointWidth; frame.beamNormals.m1.x = -frame.originWidth; frame.beamNormals.m3.x = -frame.pointWidth; frame.beamNormals.m0.y = -frame.distance; frame.beamNormals.m1.y = -frame.distance; frame.beamNormals.m2.y = -frame.distance; frame.beamNormals.m3.y = -frame.distance; float single1 = 0f; float single2 = single1; frame.beamNormals.m1.z = single1; frame.beamNormals.m0.z = single2; float single3 = frame.distanceFraction; single2 = single3; frame.beamNormals.m3.z = single3; frame.beamNormals.m2.z = single2; Color color = LaserGraphics.RangeBeamColor(beam.beamColor * single); Color color1 = color; frame.beamColor.m3 = (T)color; Color color2 = color1; color1 = color2; frame.beamColor.m2 = (T)color2; Color color3 = color1; color1 = color3; frame.beamColor.m1 = (T)color3; frame.beamColor.m0 = color1; frame.beamUVs.m0 = LaserGraphics.uv[0]; frame.beamUVs.m0.x = frame.beamUVs.m0.x * frame.distanceFraction; frame.beamUVs.m1 = LaserGraphics.uv[1]; frame.beamUVs.m1.x = frame.beamUVs.m1.x * frame.distanceFraction; frame.beamUVs.m2 = LaserGraphics.uv[2]; frame.beamUVs.m2.x = frame.beamUVs.m2.x * frame.distanceFraction; frame.beamUVs.m3 = LaserGraphics.uv[3]; frame.beamUVs.m3.x = frame.beamUVs.m3.x * frame.distanceFraction; frame.bufBeam = LaserGraphics.MeshBuffer.ForBeamMaterial(beam.beamMaterial); if (!LaserGraphics.Computation.beams.Add(frame.bufBeam)) { LaserGraphics.MeshBuffer meshBuffer = frame.bufBeam; meshBuffer.measureSize = meshBuffer.measureSize + 1; } else { frame.bufBeam.measureSize = 1; } frame.bufBeam.beams.Add(beam); if (!frame.didHit) { frame.bufDot = null; frame.drawDot = false; } else { Vector3 vector35 = LaserGraphics.world2Cam.MultiplyVector(-frame.hitNormal); if (vector35.z >= 0f) { frame.bufDot = null; frame.drawDot = false; } else { Vector3 vector36 = LaserGraphics.cam2World.MultiplyPoint(Vector3.zero); if (Physics.Linecast(vector36, Vector3.Lerp(vector36, frame.point, 0.95f), beam.cullLayers)) { frame.bufDot = null; frame.drawDot = false; } else { Vector3 vector37 = LaserGraphics.world2Cam.MultiplyPoint(frame.point); Quaternion quaternion2 = Quaternion.LookRotation(vector37, Vector3.up); frame.dotVertices1.m0 = LaserGraphics.cam2World.MultiplyPoint(vector37 + (quaternion2 * new Vector3(frame.dotRadius, -frame.dotRadius, 0f))); frame.dotVertices1.m1 = LaserGraphics.cam2World.MultiplyPoint(vector37 + (quaternion2 * new Vector3(frame.dotRadius, frame.dotRadius, 0f))); frame.dotVertices1.m2 = LaserGraphics.cam2World.MultiplyPoint(vector37 + (quaternion2 * new Vector3(-frame.dotRadius, -frame.dotRadius, 0f))); frame.dotVertices1.m3 = LaserGraphics.cam2World.MultiplyPoint(vector37 + (quaternion2 * new Vector3(-frame.dotRadius, frame.dotRadius, 0f))); quaternion2 = Quaternion.LookRotation(vector35, Vector3.up); frame.dotVertices2.m0 = LaserGraphics.cam2World.MultiplyPoint(vector37 + (quaternion2 * new Vector3(frame.dotRadius, -frame.dotRadius, -0.01f))); frame.dotVertices2.m1 = LaserGraphics.cam2World.MultiplyPoint(vector37 + (quaternion2 * new Vector3(frame.dotRadius, frame.dotRadius, -0.01f))); frame.dotVertices2.m2 = LaserGraphics.cam2World.MultiplyPoint(vector37 + (quaternion2 * new Vector3(-frame.dotRadius, -frame.dotRadius, -0.01f))); frame.dotVertices2.m3 = LaserGraphics.cam2World.MultiplyPoint(vector37 + (quaternion2 * new Vector3(-frame.dotRadius, frame.dotRadius, -0.01f))); Color color4 = LaserGraphics.RangeDotColor(beam.dotColor); color1 = color4; frame.dotColor2.m3 = (T)color4; Color color5 = color1; color1 = color5; frame.dotColor2.m2 = (T)color5; Color color6 = color1; color1 = color6; frame.dotColor2.m1 = (T)color6; Color color7 = color1; color1 = color7; frame.dotColor2.m0 = (T)color7; Color color8 = color1; color1 = color8; frame.dotColor1.m3 = (T)color8; Color color9 = color1; color1 = color9; frame.dotColor1.m2 = (T)color9; Color color10 = color1; color1 = color10; frame.dotColor1.m1 = (T)color10; frame.dotColor1.m0 = color1; frame.bufDot = LaserGraphics.MeshBuffer.ForDotMaterial(beam.dotMaterial); if (!LaserGraphics.Computation.dots.Add(frame.bufDot)) { LaserGraphics.MeshBuffer meshBuffer1 = frame.bufDot; meshBuffer1.measureSize = meshBuffer1.measureSize + 2; } else { frame.bufDot.measureSize = 2; } frame.bufDot.beams.Add(beam); frame.drawDot = true; } } } }