private static void AddToBounds(ref SourceUtils.Vector3 min, ref SourceUtils.Vector3 max, SourceUtils.Vector3 pos) { if (pos.X < min.X) { min.X = pos.X; } if (pos.Y < min.Y) { min.Y = pos.Y; } if (pos.Z < min.Z) { min.Z = pos.Z; } if (pos.X > max.X) { max.X = pos.X; } if (pos.Y > max.Y) { max.Y = pos.Y; } if (pos.Z > max.Z) { max.Z = pos.Z; } }
public AmbientPage Get([Url] string map, [Url] int page) { if (Skip) { return(null); } var bsp = Program.GetMap(map); var first = page * AmbientPage.LeavesPerPage; var count = Math.Min(first + AmbientPage.LeavesPerPage, bsp.Leaves.Length) - first; if (count < 0) { first = bsp.Leaves.Length; count = 0; } var hdr = bsp.LeafAmbientLightingHdr.Length > bsp.LeafAmbientLighting.Length; var indices = hdr ? bsp.LeafAmbientIndicesHdr : bsp.LeafAmbientIndices; var ambients = hdr ? bsp.LeafAmbientLightingHdr : bsp.LeafAmbientLighting; return(new AmbientPage { Values = Enumerable.Range(first, count).Select(x => { var leaf = bsp.Leaves[x]; var index = indices[x]; var list = new List <AmbientCube>(index.AmbientSampleCount); var min = new SourceUtils.Vector3(leaf.Min.X, leaf.Min.Y, leaf.Min.Z); var max = new SourceUtils.Vector3(leaf.Max.X, leaf.Max.Y, leaf.Max.Z); for (var i = index.FirstAmbientSample; i < index.FirstAmbientSample + index.AmbientSampleCount; ++i) { var ambient = ambients[i]; var samples = new int[6]; var relPos = new SourceUtils.Vector3(ambient.X, ambient.Y, ambient.Z) * (1f / 255f); for (var j = 0; j < 6; ++j) { samples[j] = ambient.Cube[j]; } list.Add(new AmbientCube { Position = (min + relPos * (max - min)).Rounded, Samples = samples }); } return list; }) }); }
public void VertexAttribute(VertexAttribute attrib, SourceUtils.Vector3 value) { AssertFinite(value.X); AssertFinite(value.Y); AssertFinite(value.Z); int offset; if (!_attribOffsets.TryGetValue(attrib.Index, out offset)) { return; } _vertex[offset + 0] = value.X; _vertex[offset + 1] = value.Y; _vertex[offset + 2] = value.Z; }
private static void GetDisplacementBounds(ValveBspFile bsp, int index, out SourceUtils.Vector3 min, out SourceUtils.Vector3 max, float bias = 0f) { min = new SourceUtils.Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity); max = new SourceUtils.Vector3(float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity); var disp = bsp.DisplacementManager[index]; var biasVec = disp.Normal * bias; for (var y = 0; y < disp.Size; ++y) { for (var x = 0; x < disp.Size; ++x) { var pos = disp.GetPosition(x, y); AddToBounds(ref min, ref max, pos - biasVec); AddToBounds(ref min, ref max, pos + biasVec); } } }
private static List <int> GetIntersectingClusters(BspTree tree, SourceUtils.Vector3 min, SourceUtils.Vector3 max) { if (_sLeafBuffer == null) { _sLeafBuffer = new List <BspTree.Leaf>(); } else { _sLeafBuffer.Clear(); } tree.GetIntersectingLeaves(min, max, _sLeafBuffer); var clusters = new List <int>(); foreach (var cluster in _sLeafBuffer.Select(x => x.Info.Cluster).Distinct()) { clusters.Add(cluster); } return(clusters); }
private static Vector2 GetUv(SourceUtils.Vector3 pos, TexAxis uAxis, TexAxis vAxis) { return(new Vector2( pos.Dot(uAxis.Normal) + uAxis.Offset, pos.Dot(vAxis.Normal) + vAxis.Offset)); }
public Vector3(SourceUtils.Vector3 vec) { X = vec.X; Y = vec.Y; Z = vec.Z; }