private static void CreateDefaultWaterSpecVols(RaceFile file, List <CActor> actors, CModelGroup models) { // Water specvols don't seem to be included anywhere in the map definition. We figure them out here by // looking for non-solid horizontal polygons if (file.SpecialVolumes.Count == 0) { return; } for (int i = 0; i < actors.Count; i++) { CActor actor = actors[i]; if (actor.Model == null) { continue; } CModel model = actor.Model; bool foundWater = false; Vector3 min = new Vector3(9999), max = new Vector3(-9999); List <Vector3> waterVerts = new List <Vector3>(); foreach (Polygon poly in model.Polygons) { if (poly.MaterialIndex < 0) { continue; } string materialName = actor.Model.MaterialNames == null ? "none" : actor.Model.MaterialNames[poly.MaterialIndex]; //this is a non-solid material if (materialName.StartsWith("!")) { // if this is a flat horizontal plane, mark it as water float y1 = models._vertexPositions[model.VertexBaseIndex + poly.Vertex1].Y; float y2 = models._vertexPositions[model.VertexBaseIndex + poly.Vertex2].Y; float y3 = models._vertexPositions[model.VertexBaseIndex + poly.Vertex3].Y; if (Math.Abs(y1 - y2) < 0.15f && Math.Abs(y1 - y3) < 0.15f) { foundWater = true; waterVerts.Add(Vector3.Transform(models._vertexPositions[model.VertexBaseIndex + poly.Vertex1], actor.Matrix)); waterVerts.Add(Vector3.Transform(models._vertexPositions[model.VertexBaseIndex + poly.Vertex2], actor.Matrix)); waterVerts.Add(Vector3.Transform(models._vertexPositions[model.VertexBaseIndex + poly.Vertex3], actor.Matrix)); } } } if (foundWater) { //add a bottom waterVerts.Add(new Vector3(waterVerts[0].X, waterVerts[0].Y - 6 * GameVars.Scale.Y, waterVerts[0].Z)); BoundingBox bb = BoundingBox.CreateFromPoints(waterVerts); Matrix m = Matrix.CreateScale(bb.GetSize()) * Matrix.CreateTranslation(bb.GetCenter()); SpecialVolume vol = file.SpecialVolumes[0].Copy(); //copy default water vol.Matrix = m; file.SpecialVolumes.Add(vol); } } }
private static void CreateDefaultWaterSpecVols(RaceFile file, List<CActor> actors, CModelGroup models) { // Water specvols don't seem to be included anywhere in the map definition. We figure them out here by // looking for non-solid horizontal polygons if (file.SpecialVolumes.Count == 0) return; for (int i = 0; i < actors.Count; i++) { CActor actor = actors[i]; if (actor.Model == null) continue; CModel model = actor.Model; bool foundWater = false; Vector3 min = new Vector3(9999), max = new Vector3(-9999); List<Vector3> waterVerts = new List<Vector3>(); foreach (Polygon poly in model.Polygons) { if (poly.MaterialIndex < 0) continue; string materialName = actor.Model.MaterialNames == null ? "none" : actor.Model.MaterialNames[poly.MaterialIndex]; //this is a non-solid material if (materialName.StartsWith("!")) { // if this is a flat horizontal plane, mark it as water float y1 = models._vertexPositions[model.VertexBaseIndex + poly.Vertex1].Y; float y2 = models._vertexPositions[model.VertexBaseIndex + poly.Vertex2].Y; float y3 = models._vertexPositions[model.VertexBaseIndex + poly.Vertex3].Y; if (Math.Abs(y1 - y2) < 0.15f && Math.Abs(y1 - y3) < 0.15f) { foundWater = true; waterVerts.Add(Vector3.Transform(models._vertexPositions[model.VertexBaseIndex + poly.Vertex1], actor.Matrix)); waterVerts.Add(Vector3.Transform(models._vertexPositions[model.VertexBaseIndex + poly.Vertex2], actor.Matrix)); waterVerts.Add(Vector3.Transform(models._vertexPositions[model.VertexBaseIndex + poly.Vertex3], actor.Matrix)); } } } if (foundWater) { //add a bottom waterVerts.Add(new Vector3(waterVerts[0].X, waterVerts[0].Y - 6 * GameVars.Scale.Y, waterVerts[0].Z)); BoundingBox bb = BoundingBox.CreateFromPoints(waterVerts); Matrix m = Matrix.CreateScale(bb.GetSize()) * Matrix.CreateTranslation(bb.GetCenter()); SpecialVolume vol = file.SpecialVolumes[0].Copy(); //copy default water vol.Matrix = m; file.SpecialVolumes.Add(vol); } } }