mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-10 06:34:16 +00:00
interior waters are offsetted to higher Y position
This commit is contained in:
parent
a68e42e3f1
commit
fe3e6ddb22
2 changed files with 37 additions and 13 deletions
|
@ -137,11 +137,35 @@ namespace SanAndreasUnity.Behaviours.World
|
|||
|
||||
}
|
||||
|
||||
public (Vector3 center, Vector3 size) GetCenterAndSize(WaterFace face)
|
||||
{
|
||||
Vector3 min = Vector3.positiveInfinity;
|
||||
Vector3 max = Vector3.negativeInfinity;
|
||||
for (int v = 0; v < face.Vertices.Length; v++)
|
||||
{
|
||||
min = MathUtils.MinComponents(min, face.Vertices[v].Position);
|
||||
max = MathUtils.MaxComponents(max, face.Vertices[v].Position);
|
||||
}
|
||||
|
||||
Vector3 center = (min + max) * 0.5f;
|
||||
if (this.IsInterior(center.y))
|
||||
center.y += Cell.Singleton.interiorHeightOffset;
|
||||
|
||||
Vector3 size = max - min;
|
||||
size.y = m_collisionHeight;
|
||||
|
||||
return (center, size);
|
||||
}
|
||||
|
||||
void ProcessFace(WaterFace face, Vector3[] vertices, Vector3[] normals, ref int verticesIndex, int[] indices, ref int indicesIndex)
|
||||
{
|
||||
bool isInterior = this.IsInterior(face);
|
||||
|
||||
for (int j = 0; j < face.Vertices.Length; j++)
|
||||
{
|
||||
vertices[verticesIndex + j] = face.Vertices[j].Position;
|
||||
vertices[verticesIndex + j] = isInterior
|
||||
? face.Vertices[j].Position.WithAddedY(Cell.Singleton.interiorHeightOffset)
|
||||
: face.Vertices[j].Position;
|
||||
normals[verticesIndex + j] = Vector3.up;
|
||||
}
|
||||
|
||||
|
@ -175,18 +199,8 @@ namespace SanAndreasUnity.Behaviours.World
|
|||
foreach (var face in faces)
|
||||
{
|
||||
// create box collider based on vertices
|
||||
Vector3 min = Vector3.positiveInfinity;
|
||||
Vector3 max = Vector3.negativeInfinity;
|
||||
for (int v = 0; v < face.Vertices.Length; v++)
|
||||
{
|
||||
min = MathUtils.MinComponents(min, face.Vertices[v].Position);
|
||||
max = MathUtils.MaxComponents(max, face.Vertices[v].Position);
|
||||
}
|
||||
|
||||
Vector3 center = (min + max) * 0.5f;
|
||||
|
||||
Vector3 size = max - min;
|
||||
size.y = m_collisionHeight;
|
||||
(Vector3 center, Vector3 size) = this.GetCenterAndSize(face);
|
||||
|
||||
GameObject go = availableObjects.Count > 0
|
||||
? availableObjects.Dequeue().gameObject
|
||||
|
@ -234,6 +248,16 @@ namespace SanAndreasUnity.Behaviours.World
|
|||
|
||||
}
|
||||
|
||||
public bool IsInterior(float y)
|
||||
{
|
||||
return y > 500f;
|
||||
}
|
||||
|
||||
public bool IsInterior(WaterFace face)
|
||||
{
|
||||
return this.IsInterior(this.GetCenterAndSize(face).center.y);
|
||||
}
|
||||
|
||||
void CreateQuad(Vector2 min, Vector2 max, Vector3[] vertexes, Vector3[] normals, ref int vertexIndex, int[] indexes, ref int indexesIndex)
|
||||
{
|
||||
vertexes[vertexIndex++] = new Vector3(min.x, 0f, min.y); // low left
|
||||
|
|
|
@ -97,7 +97,7 @@ namespace SanAndreasUnity.Editor
|
|||
|
||||
var waterFaceInfos = water
|
||||
.GetComponentsInChildren<WaterFaceInfo>()
|
||||
.Where(_ => _.transform.localPosition.y > 500f)
|
||||
.Where(_ => water.IsInterior(_.WaterFace))
|
||||
.Select(_ => _.gameObject)
|
||||
.ToArray();
|
||||
|
||||
|
|
Loading…
Reference in a new issue