682 lines
39 KiB
C#
682 lines
39 KiB
C#
using UnityEngine;
|
|
|
|
namespace Soundings
|
|
{
|
|
internal sealed partial class PassengerCrowd
|
|
{
|
|
private const float StepCycle = 1.10f;
|
|
private const float Turn = 2 * Mathf.PI;
|
|
private float passengerClock;
|
|
private enum FigureDetail { Hidden, Distant, Near, Close }
|
|
private enum Surface { Cloth, Skin, Hair, Accessory, Water, Contact }
|
|
|
|
private static readonly Color32 WakeTint = new(175, 221, 219, 255);
|
|
private static readonly Color32 ShadowTint = new(39, 53, 59, 255);
|
|
private static readonly Color32 StaffShirt = new(222, 222, 209, 255);
|
|
private static readonly Color32 Apron = new(49, 69, 75, 255);
|
|
private static readonly Color32 Linen = new(214, 207, 188, 255);
|
|
private static readonly Color32 EyeWhite = new(221, 213, 200, 255);
|
|
private static readonly Color32 EyeDark = new(52, 58, 55, 255);
|
|
private static readonly Color32 LipShade = new(126, 67, 64, 255);
|
|
private static readonly Color32 Strap = new(24, 43, 50, 255);
|
|
private static readonly Vector2[] Loose = Circle(6);
|
|
private static readonly Vector2[] Regular = Circle(9);
|
|
private static readonly Vector2[] Fine = Circle(12);
|
|
private static readonly Form Orb = Form.Sphere(12, 7);
|
|
private static readonly Form SmallOrb = Form.Sphere(8, 4);
|
|
private static readonly Form Torso = new(16, new[]
|
|
{
|
|
new Ring(-.024f, .104f, .069f), new Ring(.024f, .163f, .100f),
|
|
new Ring(.117f, .154f, .095f), new Ring(.200f, .145f, .100f, .012f),
|
|
new Ring(.290f, .167f, .113f, .014f), new Ring(.376f, .183f, .110f, .008f),
|
|
new Ring(.422f, .181f, .084f), new Ring(.451f, .132f, .068f),
|
|
new Ring(.471f, .078f, .053f, .009f), new Ring(.475f, .056f, .045f, .012f)
|
|
});
|
|
private static readonly Form Hips = new(12, new[]
|
|
{
|
|
new Ring(-.097f, .084f, .061f), new Ring(-.050f, .149f, .100f, -.007f),
|
|
new Ring(.014f, .169f, .105f), new Ring(.078f, .155f, .098f), new Ring(.105f, .134f, .083f)
|
|
});
|
|
private static readonly Form Head = new(24, new[]
|
|
{
|
|
new Ring(-.126f, .015f, .024f, .013f), new Ring(-.115f, .039f, .049f, .022f, .006f),
|
|
new Ring(-.092f, .062f, .066f, .013f, .008f), new Ring(-.066f, .077f, .078f, .001f, .008f),
|
|
new Ring(-.049f, .083f, .081f, -.002f, .011f), new Ring(-.028f, .088f, .084f, -.006f, .022f),
|
|
new Ring(-.012f, .091f, .085f, -.007f, .034f), new Ring(.010f, .092f, .085f, -.008f, .025f),
|
|
new Ring(.027f, .092f, .085f, -.010f, .016f), new Ring(.047f, .094f, .087f, -.011f, .007f),
|
|
new Ring(.074f, .094f, .087f, -.013f), new Ring(.105f, .086f, .080f, -.015f),
|
|
new Ring(.131f, .066f, .058f, -.021f), new Ring(.150f, .032f, .030f, -.026f),
|
|
new Ring(.157f, .001f, .001f, -.030f)
|
|
});
|
|
private static readonly Form HairCrop = Form.Hair(20, 5, .025f, .0f);
|
|
private static readonly Form HairWaves = Form.Hair(22, 6, .041f, .009f);
|
|
private static readonly Form HairTie = Form.Hair(20, 5, .043f, -.007f);
|
|
private static readonly Form Footwear = new(12, new[]
|
|
{
|
|
new Ring(-.038f, .055f, .122f, .045f), new Ring(-.027f, .064f, .140f, .048f),
|
|
new Ring(.004f, .066f, .140f, .045f), new Ring(.041f, .059f, .116f, .036f),
|
|
new Ring(.063f, .049f, .054f, -.018f), new Ring(.073f, .030f, .033f, -.016f)
|
|
});
|
|
|
|
private static readonly float[] LegStations = { 0, .13f, .30f, .42f, .50f, .60f, .74f, .88f, 1 };
|
|
private static readonly float[] LegRadii = { .084f, .093f, .081f, .068f, .058f, .057f, .060f, .042f, .035f };
|
|
private static readonly float[] ArmStations = { 0, .13f, .29f, .43f, .50f, .60f, .76f, .90f, 1 };
|
|
private static readonly float[] ArmRadii = { .060f, .070f, .061f, .049f, .046f, .045f, .040f, .031f, .025f };
|
|
|
|
private void RenderGuest(DeckGuest guest, float clock, Transform crowd, Camera view)
|
|
{
|
|
passengerClock = clock;
|
|
int seed = guest.Seed & 0x7fffffff;
|
|
float variation = Hash(seed);
|
|
float stature = Mathf.Lerp(.89f, 1.09f, variation);
|
|
float build = Mathf.Lerp(.88f, 1.14f, Hash(seed + 91));
|
|
float time = clock + Hash(seed + 15) * 65;
|
|
GuestActivity activity = guest.Activity;
|
|
bool walking = activity == GuestActivity.Walk;
|
|
bool swimming = activity == GuestActivity.Swim;
|
|
bool inWater = swimming || activity == GuestActivity.Wade;
|
|
bool staff = activity == GuestActivity.TendBar;
|
|
bool lounging = activity == GuestActivity.Lounge;
|
|
bool seated = guest.SeatHeight > 0;
|
|
float heading = guest.Heading;
|
|
float gait = 0;
|
|
Vector3 station = guest.Station;
|
|
if (walking)
|
|
{
|
|
float distance = clock * Mathf.Lerp(.84f, 1.13f, Hash(seed + 55));
|
|
station = WalkRoute(guest, distance, out heading);
|
|
gait = (distance / (StepCycle * stature)) + guest.RouteStart;
|
|
}
|
|
else if (swimming)
|
|
station = SwimRoute(guest, clock, out heading);
|
|
|
|
FigureDetail detail = ViewDetail(view, crowd.TransformPoint(station + Vector3.up * (inWater ? .21f : seated ? .63f : .87f)), stature);
|
|
if (detail == FigureDetail.Hidden)
|
|
return;
|
|
|
|
guestRotation = Quaternion.Euler(0, heading, 0);
|
|
guestMatrix = Matrix4x4.TRS(station, guestRotation, Vector3.one * stature);
|
|
coverage = (byte)Mathf.RoundToInt(guest.Presence * 255f);
|
|
Color32 shirt = staff ? StaffShirt : Shirts[seed % Shirts.Length];
|
|
Color32 pants = inWater ? Shirts[(seed / 4 + seed + 3) % Shirts.Length] : staff ? Apron : Trousers[(seed / 4 + seed) % Trousers.Length];
|
|
Color32 skin = Skin[(seed / 2 + seed) % Skin.Length];
|
|
Color32 hair = Hair[(seed / 3 + seed) % Hair.Length];
|
|
bool sleeveless = inWater;
|
|
bool swimTop = inWater && seed % 4 > 1;
|
|
float sleeveEnd = staff ? .36f : inWater ? 0 : .26f;
|
|
float trouserEnd = inWater ? .29f : !staff && seed % 5 < 2 ? .48f : 1f;
|
|
Color32 shoes = seed % 4 is 0 or 3 && !staff ? Linen : Shoes;
|
|
|
|
float phase = gait * Turn;
|
|
float breath = Mathf.Sin(time * 1.72f) * .008f;
|
|
float sway = walking ? .027f * Mathf.Sin(phase) : .021f * Mathf.Sin(time * .83f);
|
|
float hipY = seated ? (guest.SeatHeight + (lounging ? .043f : .077f)) / stature : .873f;
|
|
hipY += walking ? -.010f + .022f * Mathf.Cos(phase * 2) : breath * .23f;
|
|
float chestPitch = lounging ? -54 : seated ? 12 : walking ? 5 : 2.4f;
|
|
float chestTurn = walking ? Mathf.Sin(phase) * 7.2f : Mathf.Sin(time * .94f) * 3.8f;
|
|
float chestRoll = walking ? Mathf.Cos(phase) * 2.8f : Mathf.Sin(time * .83f) * 1.9f;
|
|
if (swimming)
|
|
{
|
|
hipY = -.100f + breath * 2.5f;
|
|
chestPitch = 84;
|
|
chestTurn = Mathf.Sin(time * 5.1f) * 4;
|
|
chestRoll = Mathf.Sin(time * 4.55f) * 17;
|
|
}
|
|
else if (inWater)
|
|
hipY = -.185f + Mathf.Sin(time * 2) * .033f;
|
|
else if (activity == GuestActivity.Rail)
|
|
chestPitch = 15 + Mathf.Sin(time * .53f) * 3;
|
|
else if (activity == GuestActivity.Revue)
|
|
hipY += .048f * Mathf.Sin(time * 6.4f);
|
|
|
|
Vector3 pelvis = new(sway, hipY, 0);
|
|
Quaternion trunk = Quaternion.Euler(chestPitch, chestTurn, chestRoll);
|
|
Vector3 headCenter = pelvis + trunk * new Vector3(0, .636f + breath, .012f);
|
|
if (swimming)
|
|
headCenter.y += .082f;
|
|
float focus = activity switch
|
|
{
|
|
GuestActivity.Read => 23f, GuestActivity.Dine => 9f, GuestActivity.Drink => 5f,
|
|
GuestActivity.TendBar => 12f, GuestActivity.Photograph => -2f, GuestActivity.Lounge => -11f,
|
|
_ => seated ? -3f : 0
|
|
};
|
|
float spot = Mathf.Sin(time * .67f) * (walking ? 12 : 23);
|
|
float breathingTurn = Mathf.SmoothStep(0, 1, Mathf.InverseLerp(.39f, .82f, Mathf.Sin(time * 2.12f)));
|
|
Quaternion face = swimming ? Quaternion.Euler(66 - 18 * breathingTurn, spot * .45f, 53 * breathingTurn)
|
|
: Quaternion.Euler(focus + Mathf.Sin(time * 1.09f) * 3.2f, spot + chestTurn * .3f, -chestRoll * .56f);
|
|
|
|
if (!inWater && detail >= FigureDetail.Near)
|
|
ContactShadow(seated ? .19f : .105f, seated ? .37f : .275f);
|
|
Shell(Hips, pelvis, new Vector3(build, 1, build), Quaternion.Euler(lounging ? -24 : chestPitch * .48f,
|
|
-chestTurn * .64f, chestRoll * -.56f), pants, Surface.Cloth);
|
|
Shell(Torso, pelvis, new Vector3(build, 1 + breath * 1.5f, Mathf.Lerp(.94f, 1.08f, build)), trunk,
|
|
inWater && !swimTop ? skin : shirt, inWater && !swimTop ? Surface.Skin : Surface.Cloth);
|
|
Vector3 throat = pelvis + trunk * new Vector3(0, .512f, .018f);
|
|
Span(throat - trunk * new Vector3(0, .06f, .004f), headCenter - face * (Vector3.up * .089f), .051f, skin, Surface.Skin);
|
|
DrawFace(detail, headCenter, face, seed, skin, hair, inWater && seed % 3 == 0);
|
|
if (detail >= FigureDetail.Near && !inWater)
|
|
DressDetails(pelvis, trunk, shirt, build, staff, seed);
|
|
if (activity == GuestActivity.Guitar)
|
|
Guitar(pelvis);
|
|
|
|
Vector2[] division = detail == FigureDetail.Close ? Fine : detail == FigureDetail.Near ? Regular : Loose;
|
|
float pour = staff ? PourBeat(time) : 0;
|
|
for (int side = -1; side <= 1; side += 2)
|
|
{
|
|
float footPhase = Mathf.Repeat(gait + (side > 0 ? .5f : 0), 1);
|
|
var (foot, toe) = FootPose(side, walking, seated, lounging, swimming, footPhase, hipY, time);
|
|
Vector3 hip = pelvis + Quaternion.Euler(0, -chestTurn * .54f, 0) * new Vector3(side * .096f * build, -.025f, 0);
|
|
Vector3 knee = lounging ? new Vector3(side * .106f, hipY + .025f, .342f)
|
|
: SolveBend(hip, ref foot, .432f, .415f, swimming ? Vector3.down : new Vector3(side * .18f, 0, 1));
|
|
Sweep(hip, knee, foot, LegStations, LegRadii, division, build, pants, skin, trouserEnd);
|
|
Shell(Footwear, foot + new Vector3(0, -.026f, 0), inWater ? new Vector3(.85f, .68f, .95f) : Vector3.one,
|
|
Quaternion.Euler(toe, side * (walking ? 2.2f : 5f), 0), inWater ? skin : shoes, inWater ? Surface.Skin : Surface.Accessory);
|
|
|
|
Vector3 shoulder = pelvis + trunk * new Vector3(side * .171f * build, .398f, .001f);
|
|
float focusPhase = staff ? pour : ActivityBeat(time, side);
|
|
Vector3 hand = HandTarget(activity, side, hipY, time, footPhase, headCenter, focusPhase, shoulder, swimTop);
|
|
Vector3 bendDirection = swimming ? new Vector3(side * .85f, .48f, -.10f) : new Vector3(side * .36f, -.82f, -.62f);
|
|
Vector3 elbow = SolveBend(shoulder, ref hand, .293f, .258f, bendDirection);
|
|
Sweep(shoulder, elbow, hand, ArmStations, ArmRadii, division, Mathf.Lerp(.88f, 1.09f, build), shirt,
|
|
skin, sleeveless ? 0 : sleeveEnd);
|
|
var handRotation = Quaternion.FromToRotation(Vector3.up, (hand - elbow).normalized);
|
|
Vector3 palm = hand + handRotation * (Vector3.up * .034f);
|
|
Shell(detail == FigureDetail.Close ? Orb : SmallOrb, palm, new Vector3(.032f, .055f, .021f), handRotation, skin, Surface.Skin);
|
|
if (detail == FigureDetail.Close)
|
|
Shell(SmallOrb, palm + handRotation * new Vector3(-side * .027f, .002f, .008f),
|
|
new Vector3(.015f, .035f, .014f), handRotation * Quaternion.Euler(0, 0, side * -22), skin, Surface.Skin);
|
|
if (side > 0)
|
|
HeldObject(activity, palm, yaw: chestTurn, lift: focusPhase);
|
|
else if (staff)
|
|
Shell(SmallOrb, palm + new Vector3(.022f, .034f, .015f), new Vector3(.034f, .048f, .035f),
|
|
Quaternion.identity, Glass, Surface.Accessory);
|
|
}
|
|
if (inWater)
|
|
PoolRipples(swimming, time);
|
|
}
|
|
|
|
private static FigureDetail ViewDetail(Camera view, Vector3 center, float stature)
|
|
{
|
|
Vector3 point = view.WorldToViewportPoint(center);
|
|
if (point.z <= .06f)
|
|
return FigureDetail.Hidden;
|
|
float frameHeight = view.targetTexture != null ? view.targetTexture.height : Screen.height;
|
|
float span = view.orthographic ? 2 * view.orthographicSize
|
|
: 2 * point.z * Mathf.Tan(view.fieldOfView * Mathf.Deg2Rad * .5f);
|
|
float height = 1.78f * stature / Mathf.Max(.1f, span);
|
|
float margin = .025f + height * .62f;
|
|
if (point.x < -margin / view.aspect || point.x > 1 + margin / view.aspect || point.y < -margin || point.y > 1 + margin)
|
|
return FigureDetail.Hidden;
|
|
float pixels = frameHeight * height;
|
|
return pixels > 250 ? FigureDetail.Close : pixels > 76 ? FigureDetail.Near : FigureDetail.Distant;
|
|
}
|
|
|
|
private static Vector3 SwimRoute(DeckGuest guest, float clock, out float heading)
|
|
{
|
|
float limit = Mathf.Max(.1f, guest.SwimHalfLength);
|
|
float phase = Mathf.Repeat(clock * .78f / (limit * Turn) + Hash(guest.Seed + 29), 1);
|
|
float turn = Mathf.SmoothStep(0, 1, Mathf.InverseLerp(.437f, .563f, phase));
|
|
float turnaround = phase < .25f ? Mathf.SmoothStep(-1, 0, Mathf.InverseLerp(-.055f, .055f, phase))
|
|
: Mathf.SmoothStep(0, 1, Mathf.InverseLerp(.945f, 1.055f, phase));
|
|
heading = guest.Heading + (turn + turnaround) * 180;
|
|
return guest.Station + Quaternion.Euler(0, guest.Heading, 0) * new Vector3(0, 0, -Mathf.Cos(phase * Turn) * limit);
|
|
}
|
|
|
|
private static (Vector3 Foot, float Toe) FootPose(int side, bool walking, bool seated, bool lounging, bool swimming,
|
|
float phase, float hip, float clock)
|
|
{
|
|
if (swimming)
|
|
return (new Vector3(side * .092f, hip - .13f + .081f * Mathf.Sin(clock * 8.5f + side * 1.57f), -.79f), -81);
|
|
if (lounging)
|
|
return (new Vector3(side * .102f, hip - .06f, .72f), -18);
|
|
if (seated)
|
|
return (new Vector3(side * .122f, Mathf.Max(.075f, hip - .50f), .434f), -3);
|
|
if (!walking)
|
|
return (new Vector3(side * .107f, .065f, side * .066f), 0);
|
|
|
|
const float stance = .605f;
|
|
const float heel = .331f;
|
|
float z = heel - phase * StepCycle;
|
|
if (phase < stance)
|
|
{
|
|
float toe = -13 * (1 - Mathf.SmoothStep(0, 1, phase / .18f)) + 22 * Mathf.SmoothStep(0, 1, (phase - .43f) / .175f);
|
|
float ankleLift = .036f * Mathf.Abs(toe) / 22;
|
|
return (new Vector3(side * .101f, .065f + ankleLift, z), toe);
|
|
}
|
|
float swing = (phase - stance) / (1 - stance);
|
|
float lifted = Mathf.Sin(Mathf.PI * swing);
|
|
z = Mathf.Lerp(heel - stance * StepCycle, heel, Mathf.SmoothStep(0, 1, swing));
|
|
float rollHeight = Mathf.Lerp(.036f, .036f * 13 / 22, swing);
|
|
return (new Vector3(side * .101f, .065f + .128f * lifted + rollHeight, z),
|
|
Mathf.Lerp(22, -13, swing) + 11 * lifted);
|
|
}
|
|
|
|
private static Vector3 SolveBend(Vector3 root, ref Vector3 tip, float upper, float lower, Vector3 toward)
|
|
{
|
|
Vector3 difference = tip - root;
|
|
float requested = difference.magnitude;
|
|
if (requested < .001f)
|
|
return root + toward.normalized * upper;
|
|
Vector3 axis = difference / requested;
|
|
float distance = Mathf.Min(requested, upper + lower - .002f);
|
|
tip = root + axis * distance;
|
|
float along = Mathf.Clamp((distance * distance + upper * upper - lower * lower) / (2 * distance), -upper, upper);
|
|
Vector3 bend = Vector3.ProjectOnPlane(toward, axis).normalized;
|
|
return root + axis * along + bend * Mathf.Sqrt(upper * upper - along * along);
|
|
}
|
|
|
|
private static float ActivityBeat(float clock, int side)
|
|
{
|
|
float phase = Mathf.Repeat(clock * (side > 0 ? .174f : .136f) + (side < 0 ? .23f : 0), 1);
|
|
return Mathf.SmoothStep(0, 1, (phase - .22f) / .16f) * (1 - Mathf.SmoothStep(0, 1, (phase - .54f) / .21f));
|
|
}
|
|
|
|
private static float PourBeat(float clock)
|
|
{
|
|
float phase = Mathf.Repeat(clock * .19f, 1);
|
|
return Mathf.SmoothStep(0, 1, (phase - .24f) / .16f) * (1 - Mathf.SmoothStep(0, 1, (phase - .63f) / .15f));
|
|
}
|
|
|
|
private static Vector3 HandTarget(GuestActivity activity, int side, float hip, float time, float footPhase,
|
|
Vector3 head, float beat, Vector3 shoulder, bool swimTop)
|
|
{
|
|
switch (activity)
|
|
{
|
|
case GuestActivity.Walk:
|
|
return new Vector3(side * .198f, hip - .070f + .063f * Mathf.Abs(Mathf.Cos(footPhase * Turn)),
|
|
-.175f * Mathf.Cos(footPhase * Turn) + .023f);
|
|
case GuestActivity.Rail:
|
|
return new Vector3(side * .145f, hip + .167f + .008f * Mathf.Sin(time * 1.6f), .42f);
|
|
case GuestActivity.Read:
|
|
return new Vector3(side * (.091f + .025f * beat), hip + .294f + .026f * beat, .354f);
|
|
case GuestActivity.Dine:
|
|
case GuestActivity.Drink:
|
|
Vector3 table = new(side * .146f, hip + (activity == GuestActivity.Dine ? .165f : .178f),
|
|
.43f);
|
|
Vector3 lips = head + new Vector3(.036f, -.047f, .104f);
|
|
return side > 0 ? Vector3.Lerp(table, lips, beat) : table + new Vector3(.022f * beat, .006f, -.037f * beat);
|
|
case GuestActivity.TendBar:
|
|
return side > 0 ? new Vector3(.19f + .12f * Mathf.Sin(time * 1.35f) * (1 - beat), hip + .14f + .22f * beat, .50f - .069f * beat)
|
|
: new Vector3(-.119f + .072f * Mathf.Sin(time * 1.55f) * (1 - beat), hip + .158f, .49f);
|
|
case GuestActivity.Watch:
|
|
float clap = beat * (.66f + .34f * Mathf.Sin(time * 17f));
|
|
return new Vector3(side * Mathf.Lerp(.155f, .031f, clap), hip + .108f + beat * .25f, .295f + beat * .055f);
|
|
case GuestActivity.Photograph:
|
|
return Vector3.Lerp(new Vector3(side * .082f, hip + .28f, .285f), head + new Vector3(side * .065f, -.034f, .182f), beat);
|
|
case GuestActivity.Talk:
|
|
return new Vector3(side * (.203f + beat * .147f), hip - .065f + beat * (.29f + .04f * Mathf.Sin(time * 5.2f)),
|
|
.075f + .25f * beat);
|
|
case GuestActivity.Perform:
|
|
return side > 0 ? head + new Vector3(.061f, -.104f, .09f)
|
|
: new Vector3(-.223f - beat * .259f, hip + .17f + beat * .41f, .12f + beat * .12f);
|
|
case GuestActivity.Guitar:
|
|
return side > 0 ? new Vector3(.109f + Mathf.Sin(time * 10.4f) * .046f, hip + .26f + Mathf.Sin(time * 10.4f) * .065f, .30f)
|
|
: new Vector3(-.25f + Mathf.Sin(time * 2.35f) * .032f, hip + .46f, .27f);
|
|
case GuestActivity.Revue:
|
|
float rhythm = time * 3.19f + side * 1.17f;
|
|
return new Vector3(side * (.276f + Mathf.Cos(rhythm) * .214f), hip + .42f + Mathf.Sin(rhythm) * .38f, .24f);
|
|
case GuestActivity.Lounge:
|
|
return new Vector3(side * .207f, hip + .067f + .018f * beat, .185f);
|
|
case GuestActivity.Swim:
|
|
float stroke = Mathf.Repeat(time * .91f + (side > 0 ? .5f : 0), 1);
|
|
float recover = stroke / .40f;
|
|
float pull = (stroke - .40f) / .60f;
|
|
if (stroke < .40f)
|
|
return new Vector3(side * (.305f - .067f * recover), shoulder.y + .044f + .297f * Mathf.Sin(recover * Mathf.PI),
|
|
Mathf.Lerp(shoulder.z - .46f, shoulder.z + .44f, Mathf.SmoothStep(0, 1, recover)));
|
|
float arc = Mathf.Sin(pull * Mathf.PI);
|
|
return new Vector3(side * (Mathf.Lerp(.238f, .305f, pull) + .04f * arc), shoulder.y + .044f - .205f * arc,
|
|
Mathf.Lerp(shoulder.z + .44f, shoulder.z - .46f, Mathf.SmoothStep(0, 1, pull)));
|
|
case GuestActivity.Wade:
|
|
float tread = time * 2.58f + side * 1.8f;
|
|
return new Vector3(side * (.267f + .11f * Mathf.Cos(tread)), .033f + .061f * Mathf.Sin(tread),
|
|
.17f + (swimTop ? .105f : .15f) * Mathf.Sin(tread));
|
|
default:
|
|
return new Vector3(side * .148f, hip + .063f, .27f);
|
|
}
|
|
}
|
|
|
|
private void DrawFace(FigureDetail detail, Vector3 center, Quaternion angle, int seed, Color32 skin, Color32 hair, bool cap)
|
|
{
|
|
float width = Mathf.Lerp(.90f, 1.08f, Hash(seed + 540));
|
|
Shell(detail == FigureDetail.Distant ? Orb : Head, center, detail == FigureDetail.Distant
|
|
? new Vector3(.091f * width, .133f, .089f) : new Vector3(width, 1, 1), angle, skin, Surface.Skin);
|
|
int style = seed % 7;
|
|
if (cap)
|
|
{
|
|
Shell(HairCrop, center, new Vector3(1.04f, .98f, 1.04f), angle, Shirts[seed % Shirts.Length], Surface.Cloth);
|
|
}
|
|
else if (style != 6)
|
|
{
|
|
Form shape = style is 2 or 5 ? HairWaves : style == 4 ? HairTie : HairCrop;
|
|
Shell(shape, center, new Vector3(width, 1, 1), angle, hair, Surface.Hair);
|
|
if (style == 4)
|
|
Shell(Orb, center + angle * new Vector3(.014f, .023f, -.116f), new Vector3(.055f, .066f, .053f), angle,
|
|
hair, Surface.Hair);
|
|
}
|
|
if (detail == FigureDetail.Distant)
|
|
return;
|
|
float blink = Mathf.Repeat(TimeForBlink(seed), 1);
|
|
bool spectacles = !cap && seed % 11 == 2;
|
|
for (int side = -1; side <= 1; side += 2)
|
|
{
|
|
var ear = new Vector3(side * .084f * width, -.016f, -.018f);
|
|
Shell(SmallOrb, center + angle * ear, new Vector3(.018f, .033f, .023f), angle * Quaternion.Euler(0, 0, side * -12), skin, Surface.Skin);
|
|
if (detail != FigureDetail.Close)
|
|
continue;
|
|
Shell(SmallOrb, center + angle * (ear + new Vector3(side * .010f, .001f, .012f)), new Vector3(.007f, .020f, .008f),
|
|
angle, Color32.Lerp(skin, LipShade, .24f), Surface.Skin);
|
|
float x = side * .037f * width;
|
|
Quaternion eyes = angle * Quaternion.Euler(0, side * 14, side * 1.4f);
|
|
if (spectacles)
|
|
{
|
|
Shell(SmallOrb, center + angle * new Vector3(x * 1.12f, .029f, .081f), new Vector3(.032f, .020f, .011f),
|
|
eyes, Dark, Surface.Accessory);
|
|
continue;
|
|
}
|
|
float open = blink < .036f ? .25f + .75f * Mathf.Abs(blink / .018f - 1) : 1;
|
|
var eye = new Vector3(x, .026f, .070f);
|
|
Shell(SmallOrb, center + angle * (eye), new Vector3(.019f, .008f, .010f), eyes,
|
|
Color32.Lerp(skin, Dark, .43f), Surface.Skin);
|
|
Shell(SmallOrb, center + angle * (eye + Vector3.forward * .005f), new Vector3(.014f, .0054f * open, .007f), eyes,
|
|
EyeWhite, Surface.Accessory);
|
|
Shell(SmallOrb, center + angle * (eye + new Vector3(.001f, 0, .0107f)), new Vector3(.0054f, .0052f * open, .0034f), eyes,
|
|
EyeDark, Surface.Accessory);
|
|
Shell(SmallOrb, center + angle * new Vector3(x, .044f, .073f), new Vector3(.018f, .0031f, .005f), eyes,
|
|
Color32.Lerp(hair, skin, .19f), Surface.Hair);
|
|
}
|
|
if (detail == FigureDetail.Close)
|
|
{
|
|
Shell(SmallOrb, center + angle * new Vector3(0, -.049f, .091f), new Vector3(.024f, .0045f, .007f), angle,
|
|
Color32.Lerp(skin, LipShade, .37f), Surface.Skin);
|
|
if (spectacles)
|
|
Span(center + angle * new Vector3(-.020f, .033f, .095f), center + angle * new Vector3(.020f, .033f, .095f),
|
|
.005f, Dark, Surface.Accessory);
|
|
}
|
|
}
|
|
|
|
private float TimeForBlink(int seed) => passengerClock * Mathf.Lerp(.152f, .250f, Hash(seed + 217)) + Hash(seed + 40);
|
|
|
|
private void DressDetails(Vector3 pelvis, Quaternion trunk, Color32 shirt, float build, bool staff, int seed)
|
|
{
|
|
var lean = pelvis + trunk * new Vector3(0, .307f, .114f);
|
|
if (staff)
|
|
{
|
|
Shell(SmallOrb, lean + trunk * new Vector3(0, -.137f, .001f), new Vector3(.116f * build, .228f, .021f), trunk, Apron, Surface.Cloth);
|
|
Shell(SmallOrb, lean + trunk * new Vector3(0, .076f, -.005f), new Vector3(.055f, .075f, .020f), trunk,
|
|
Color32.Lerp(shirt, Linen, .52f), Surface.Cloth);
|
|
Shell(SmallOrb, lean + trunk * new Vector3(.094f, .093f, .001f), new Vector3(.024f, .010f, .011f), trunk,
|
|
Linen, Surface.Accessory);
|
|
}
|
|
else if (seed % 3 == 1)
|
|
{
|
|
Color32 trim = Color32.Lerp(shirt, Linen, .25f);
|
|
for (int side = -1; side <= 1; side += 2)
|
|
Span(pelvis + trunk * new Vector3(side * .041f, .468f, .051f), pelvis + trunk * new Vector3(side * .021f, .400f, .093f),
|
|
.016f, trim, Surface.Cloth);
|
|
for (int i = 0; i < 2; i++)
|
|
Shell(SmallOrb, pelvis + trunk * new Vector3(0, .365f - i * .046f, .123f), Vector3.one * .007f, trunk,
|
|
trim, Surface.Accessory);
|
|
}
|
|
}
|
|
|
|
private void HeldObject(GuestActivity activity, Vector3 palm, float yaw, float lift)
|
|
{
|
|
switch (activity)
|
|
{
|
|
case GuestActivity.Drink:
|
|
Quaternion tilt = Quaternion.Euler(-15 - 37 * lift, yaw, 7);
|
|
Vector3 bowl = palm + tilt * new Vector3(-.017f, .047f, .021f);
|
|
Shell(SmallOrb, bowl, new Vector3(.035f, .042f, .035f), tilt, Glass, Surface.Accessory);
|
|
Shell(SmallOrb, bowl + tilt * (Vector3.up * .020f), new Vector3(.029f, .015f, .029f), tilt, Paper, Surface.Accessory);
|
|
Span(bowl - tilt * (Vector3.up * .031f), bowl - tilt * (Vector3.up * .077f), .008f, Linen, Surface.Accessory);
|
|
Shell(SmallOrb, bowl - tilt * (Vector3.up * .076f), new Vector3(.026f, .004f, .026f), tilt, Linen, Surface.Accessory);
|
|
break;
|
|
case GuestActivity.Dine:
|
|
Span(palm + new Vector3(-.012f, 0, -.02f), palm + new Vector3(-.013f, .021f * lift, .095f), .006f, Linen, Surface.Accessory);
|
|
break;
|
|
case GuestActivity.Read:
|
|
Shell(SmallOrb, palm + new Vector3(-.068f, .038f, .028f), new Vector3(.106f, .065f, .011f), Quaternion.Euler(-45, yaw, 0),
|
|
Paper, Surface.Accessory);
|
|
break;
|
|
case GuestActivity.Photograph:
|
|
Shell(SmallOrb, palm + new Vector3(-.036f, .044f, .009f), new Vector3(.037f, .065f, .009f), Quaternion.Euler(-12 + lift * 23, yaw, 0),
|
|
Strap, Surface.Accessory);
|
|
break;
|
|
case GuestActivity.Perform:
|
|
Span(palm + new Vector3(-.009f, -.029f, .023f), palm + new Vector3(-.035f, .105f, .030f), .019f, Dark, Surface.Accessory);
|
|
break;
|
|
case GuestActivity.TendBar:
|
|
float phase = Mathf.Repeat(passengerClock * .19f, 1);
|
|
Quaternion bottle = Quaternion.Euler(-28 - 48 * lift, yaw + phase * 5, -11 + lift * 87);
|
|
Shell(Orb, palm + bottle * new Vector3(-.023f, .067f, 0), new Vector3(.031f, .084f, .031f), bottle,
|
|
Apron, Surface.Accessory);
|
|
Span(palm + bottle * new Vector3(-.023f, .120f, 0), palm + bottle * new Vector3(-.023f, .183f, 0),
|
|
.019f, Apron, Surface.Accessory);
|
|
Shell(SmallOrb, palm + bottle * new Vector3(-.023f, .079f, 0), new Vector3(.032f, .027f, .032f), bottle,
|
|
Paper, Surface.Accessory);
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void Guitar(Vector3 pelvis)
|
|
{
|
|
Quaternion angle = Quaternion.Euler(-11, -5, 20);
|
|
Shell(Orb, pelvis + new Vector3(.104f, .269f, .211f), new Vector3(.153f, .167f, .054f), angle, Paper, Surface.Accessory);
|
|
Shell(Orb, pelvis + new Vector3(-.005f, .364f, .227f), new Vector3(.107f, .115f, .043f), angle, Paper, Surface.Accessory);
|
|
Shell(SmallOrb, pelvis + new Vector3(.055f, .332f, .277f), new Vector3(.032f, .035f, .008f), angle, Dark, Surface.Accessory);
|
|
Span(pelvis + new Vector3(.034f, .306f, .255f), pelvis + new Vector3(-.328f, .559f, .264f), .023f, Shoes, Surface.Accessory);
|
|
}
|
|
|
|
private void ContactShadow(float width, float length)
|
|
{
|
|
int start = vertices.Count;
|
|
byte alpha = (byte)(coverage * .38f);
|
|
Emit(new Vector3(0, .012f, .042f), Vector3.up, ShadowTint, Surface.Contact, alpha);
|
|
foreach (Vector2 point in Fine)
|
|
Emit(new Vector3(point.x * width, .012f, .042f + point.y * length), Vector3.up, ShadowTint, Surface.Contact, 0);
|
|
for (int edge = 0; edge < Fine.Length; edge++)
|
|
{
|
|
indices.Add(start);
|
|
indices.Add(start + 1 + edge);
|
|
indices.Add(start + 1 + (edge + 1) % Fine.Length);
|
|
}
|
|
}
|
|
|
|
private void PoolRipples(bool swimming, float time)
|
|
{
|
|
for (int ring = 0; ring < 2; ring++)
|
|
{
|
|
float age = Mathf.Repeat(time * (swimming ? 1.83f : .99f) + ring * .5f, 1);
|
|
float span = Mathf.Lerp(.24f, .61f, age);
|
|
float depth = span * (swimming ? .51f : .64f);
|
|
float wakeZ = swimming ? -.36f - age * .22f : -.016f;
|
|
int start = vertices.Count;
|
|
byte alpha = (byte)(coverage * Mathf.Sin(age * Mathf.PI) * (swimming ? .55f : .34f));
|
|
const int sections = 10;
|
|
for (int step = 0; step <= sections; step++)
|
|
{
|
|
float phase = Mathf.Lerp(swimming ? .94f : .49f, swimming ? 5.20f : 5.89f, step / (float)sections);
|
|
float x = Mathf.Sin(phase), z = Mathf.Cos(phase);
|
|
float thickness = .018f * (.78f + .22f * Mathf.Sin(phase * 3 + time));
|
|
Emit(new Vector3(x * span, .016f, wakeZ + z * depth), Vector3.up, WakeTint, Surface.Water, alpha);
|
|
Emit(new Vector3(x * (span + thickness), .016f, wakeZ + z * (depth + thickness)), Vector3.up, WakeTint, Surface.Water, alpha);
|
|
if (step > 0)
|
|
{
|
|
int a = start + (step - 1) * 2;
|
|
TrianglePair(a, a + 1, a + 3, a + 2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Sweep(Vector3 top, Vector3 middle, Vector3 bottom, float[] stations, float[] radii, Vector2[] division,
|
|
float build, Color32 cloth, Color32 skin, float covered)
|
|
{
|
|
int start = vertices.Count;
|
|
Vector3 upper = (middle - top).normalized;
|
|
Vector3 lower = (bottom - middle).normalized;
|
|
for (int i = 0; i < stations.Length; i++)
|
|
{
|
|
float t = stations[i];
|
|
Vector3 center = t < .5f ? Vector3.Lerp(top, middle, 2 * t) : Vector3.Lerp(middle, bottom, 2 * t - 1);
|
|
float round = Mathf.SmoothStep(0, 1, (t - .31f) / .37f);
|
|
Vector3 axis = Vector3.Lerp(upper, lower, round).normalized;
|
|
Vector3 across = Vector3.ProjectOnPlane(Mathf.Abs(axis.x) < .91f ? Vector3.right : Vector3.forward, axis).normalized;
|
|
Vector3 depth = Vector3.Cross(across, axis);
|
|
float radius = radii[i] * build;
|
|
bool dressed = t <= covered && covered > 0;
|
|
Color32 color = dressed ? cloth : skin;
|
|
foreach (Vector2 point in division)
|
|
{
|
|
Vector3 offset = across * point.x + depth * point.y;
|
|
Emit(center + radius * offset, offset, color, dressed ? Surface.Cloth : Surface.Skin, coverage);
|
|
}
|
|
}
|
|
RingFaces(start, division.Length, stations.Length);
|
|
}
|
|
|
|
private void Span(Vector3 from, Vector3 to, float radius, Color32 color, Surface kind)
|
|
{
|
|
Vector3 direction = to - from;
|
|
float length = direction.magnitude;
|
|
if (length > .001f)
|
|
Shell(SmallOrb, (from + to) * .5f, new Vector3(radius, length * .66f, radius), Quaternion.FromToRotation(Vector3.up,
|
|
direction / length), color, kind);
|
|
}
|
|
|
|
private void Shell(Form form, Vector3 center, Vector3 size, Quaternion rotation, Color32 color, Surface kind)
|
|
{
|
|
int start = vertices.Count;
|
|
Matrix4x4 position = Matrix4x4.TRS(center, rotation, size);
|
|
Vector3 inverse = new(1 / size.x, 1 / size.y, 1 / size.z);
|
|
for (int i = 0; i < form.Points.Length; i++)
|
|
{
|
|
Vector3 point = position.MultiplyPoint3x4(form.Points[i]);
|
|
Vector3 normal = rotation * Vector3.Scale(form.Normals[i], inverse).normalized;
|
|
Emit(point, normal, color, kind, coverage);
|
|
}
|
|
foreach (int index in form.Indices)
|
|
indices.Add(start + index);
|
|
}
|
|
|
|
private void Emit(Vector3 point, Vector3 normal, Color32 color, Surface kind, byte alpha)
|
|
{
|
|
color.a = alpha;
|
|
colors.Add(color);
|
|
vertices.Add(guestMatrix.MultiplyPoint3x4(point));
|
|
normals.Add(guestRotation * normal);
|
|
surface.Add(new Vector4(point.x, point.y, point.z, (int)kind));
|
|
}
|
|
|
|
private void RingFaces(int start, int sides, int rings)
|
|
{
|
|
for (int ring = 0; ring < rings - 1; ring++)
|
|
for (int i = 0; i < sides; i++)
|
|
{
|
|
int a = start + ring * sides + i;
|
|
int b = start + ring * sides + (i + 1) % sides;
|
|
TrianglePair(a, b, b + sides, a + sides);
|
|
}
|
|
}
|
|
|
|
private void TrianglePair(int a, int b, int c, int d)
|
|
{
|
|
indices.Add(a);
|
|
indices.Add(b);
|
|
indices.Add(c);
|
|
indices.Add(a);
|
|
indices.Add(c);
|
|
indices.Add(d);
|
|
}
|
|
|
|
private static Vector2[] Circle(int sides)
|
|
{
|
|
var points = new Vector2[sides];
|
|
for (int i = 0; i < sides; i++)
|
|
{
|
|
float angle = Turn * i / sides;
|
|
points[i] = new Vector2(Mathf.Sin(angle), Mathf.Cos(angle));
|
|
}
|
|
return points;
|
|
}
|
|
|
|
private readonly struct Ring
|
|
{
|
|
internal readonly float Height, Width, Depth, Shift, Nose;
|
|
|
|
internal Ring(float height, float width, float depth, float shift = 0, float nose = 0)
|
|
{
|
|
Height = height;
|
|
Width = width;
|
|
Depth = depth;
|
|
Shift = shift;
|
|
Nose = nose;
|
|
}
|
|
}
|
|
|
|
private sealed class Form
|
|
{
|
|
internal readonly Vector3[] Points, Normals;
|
|
internal readonly int[] Indices;
|
|
|
|
internal Form(int sides, Ring[] rings) : this(sides, rings.Length, (band, angle) =>
|
|
{
|
|
Ring ring = rings[band];
|
|
float front = Mathf.Pow(Mathf.Max(0, 1 - Mathf.Abs(angle.x) * 2.6f), 2) * Mathf.Max(0, angle.y);
|
|
return new Vector3(ring.Width * angle.x, ring.Height, ring.Shift + ring.Depth * angle.y + ring.Nose * front);
|
|
}) { }
|
|
|
|
private Form(int sides, int bands, System.Func<int, Vector2, Vector3> point)
|
|
{
|
|
Points = new Vector3[sides * bands];
|
|
Normals = new Vector3[Points.Length];
|
|
Indices = new int[sides * (bands - 1) * 6];
|
|
Vector2[] circle = Circle(sides);
|
|
for (int band = 0; band < bands; band++)
|
|
for (int side = 0; side < sides; side++)
|
|
{
|
|
int a = band * sides + side;
|
|
Points[a] = point(band, circle[side]);
|
|
if (band == bands - 1)
|
|
continue;
|
|
int b = band * sides + (side + 1) % sides;
|
|
int index = a * 6;
|
|
Indices[index] = a;
|
|
Indices[index + 1] = b;
|
|
Indices[index + 2] = b + sides;
|
|
Indices[index + 3] = a;
|
|
Indices[index + 4] = b + sides;
|
|
Indices[index + 5] = a + sides;
|
|
}
|
|
for (int i = 0; i < Indices.Length; i += 3)
|
|
{
|
|
int a = Indices[i], b = Indices[i + 1], c = Indices[i + 2];
|
|
Vector3 normal = Vector3.Cross(Points[b] - Points[a], Points[c] - Points[a]);
|
|
Normals[a] += normal;
|
|
Normals[b] += normal;
|
|
Normals[c] += normal;
|
|
}
|
|
for (int i = 0; i < Normals.Length; i++)
|
|
Normals[i].Normalize();
|
|
}
|
|
|
|
internal static Form Sphere(int sides, int bands) => new(sides, bands + 1, (band, angle) =>
|
|
{
|
|
float latitude = (band / (float)bands - .5f) * Mathf.PI * .9999f;
|
|
return new Vector3(angle.x * Mathf.Cos(latitude), Mathf.Sin(latitude), angle.y * Mathf.Cos(latitude));
|
|
});
|
|
|
|
internal static Form Hair(int sides, int bands, float fringe, float wave) => new(sides, bands + 1, (band, angle) =>
|
|
{
|
|
float heading = Mathf.Atan2(angle.x, angle.y);
|
|
float slope = .19f + .77f * angle.y + Mathf.Abs(angle.x) * fringe * 6 + wave * 19 * Mathf.Sin(heading * 3 + .67f);
|
|
float latitude = Mathf.Lerp(slope, 1.5707f, band / (float)bands);
|
|
float part = 1 + .03f * Mathf.Cos(heading * 6.9f + latitude * 1.31f);
|
|
return new Vector3(.102f * angle.x * Mathf.Cos(latitude) * part, .041f + Mathf.Sin(latitude) * (.122f + wave),
|
|
-.026f + .103f * angle.y * Mathf.Cos(latitude) * part);
|
|
});
|
|
}
|
|
}
|
|
}
|