patternProjectionUtil.py (3608B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\cosmetics\ship\pages\studio\patternProjectionUtil.py 2 import math 3 import geo2 4 5 def get_pattern_projection_position_and_rotation(ellipsoid_center, ellipsoid_radii, offset_x, offset_y, yaw, pitch, twist): 6 projector_pos = get_projector_position(yaw, pitch, ellipsoid_center, ellipsoid_radii) 7 pre_twist_quat = _get_pre_twist_quat(projector_pos, pitch, ellipsoid_center, ellipsoid_radii) 8 x_y_offset = _get_x_y_offset_vector(pre_twist_quat, offset_x, offset_y, ellipsoid_radii) 9 position = geo2.Vec3Add(projector_pos, x_y_offset) 10 twist_quat = geo2.QuaternionRotationSetYawPitchRoll(0.0, twist * math.pi, 0.0) 11 rotation = geo2.QuaternionMultiply(twist_quat, pre_twist_quat) 12 return (list(position), list(rotation)) 13 14 15 def get_projector_position(yaw, pitch, ellipsoid_center, ellipsoid_radii): 16 intersection_point = _get_ellipsoid_intersection_point(ellipsoid_radii, yaw, pitch) 17 projector_pos = geo2.Vec3Add(ellipsoid_center, intersection_point) 18 return projector_pos 19 20 21 def _get_ellipsoid_intersection_point(ellipsoid_radii, yaw, pitch): 22 abs_pitch = math.fabs(pitch) 23 x = math.sin(yaw * math.pi) * ellipsoid_radii[0] * (1.0 - abs_pitch) 24 y = abs_pitch * ellipsoid_radii[1] * math.copysign(1.0, pitch) 25 z = math.cos(yaw * math.pi) * -ellipsoid_radii[2] * (1 - abs_pitch) 26 x_y_offset = (x, y, z) 27 x_y_offset = geo2.Vec3Scale(geo2.Vec3Normalize(x_y_offset), max(ellipsoid_radii)) 28 return x_y_offset 29 30 31 def _get_projection_point_offset(ellipsoid_radii, projectionPoint): 32 maxSideLength = max(ellipsoid_radii) 33 directionScaler = (ellipsoid_radii[0] / maxSideLength, ellipsoid_radii[1] / maxSideLength, ellipsoid_radii[2] / maxSideLength) 34 offsetFactor = 0.2 35 projectionPointNormalized = geo2.Vec3Normalize(projectionPoint) 36 offsetAtPosition = tuple((ele1 * ele2 * ele3 * offsetFactor for ele1, ele2, ele3 in zip(projectionPointNormalized, ellipsoid_radii, directionScaler))) 37 return offsetAtPosition 38 39 40 def _get_pre_twist_quat(projection_pos, pitch, ellipsoid_center, ellipsoid_radii): 41 offset_at_position = _get_projection_point_offset(ellipsoid_radii, projection_pos) 42 targetPoint = geo2.Vec3Add(ellipsoid_center, offset_at_position) 43 lerpValue = math.pow(min(1.0, 1.2 * abs(pitch)), 2.0) 44 targetPoint = geo2.Lerp(targetPoint, ellipsoid_center, lerpValue) 45 directionNormalized = geo2.Vec3Normalize(geo2.Vec3Subtract(targetPoint, projection_pos)) 46 lookingAtLeftSide = 0.0 < directionNormalized[0] 47 rotationQuat = geo2.QuaternionRotationArc((0.0, 1.0, 0.0), directionNormalized) 48 x, _, z = directionNormalized 49 yaw = -(math.atan2(z, x) + math.pi / 2) 50 horizontalAxisMapped = yaw % math.pi / math.pi 51 if lookingAtLeftSide: 52 horizontalAxisMapped = 1.0 - horizontalAxisMapped / 2 53 else: 54 horizontalAxisMapped = 0.5 - horizontalAxisMapped / 2 55 flip = math.pi if yaw % math.pi == 0.0 else 0.0 56 rollValue = horizontalAxisMapped * 2.0 * -math.pi + flip 57 rollQuaternion = geo2.QuaternionRotationSetYawPitchRoll(0.0, rollValue, 0.0) 58 Y2Zadjustment = (0.0, 0.0, 0.7071, 0.7071) 59 rotationQuat = geo2.QuaternionMultiply(Y2Zadjustment, rotationQuat) 60 rotationQuat = geo2.QuaternionMultiply(rollQuaternion, rotationQuat) 61 return rotationQuat 62 63 64 def _get_x_y_offset_vector(rotation, offset_x, offset_y, ellipsoid_radii): 65 offset = (0.0, offset_x, -offset_y) 66 scaledOffset = geo2.Vec3Scale(offset, max(ellipsoid_radii) * 0.75) 67 return geo2.QuaternionTransformVector(rotation, scaledOffset)