public static bool GetItemsInFrustum(Plane[] planes, HashSet <GameObject> objectsInFrustum) { if (objectsInFrustum == null) { return(false); } objectsInFrustum.Clear(); var found = false; foreach (var model in InternalCSGModelManager.Models) { if (!ModelTraits.WillModelRender(model)) { continue; } found = InternalCSGModelManager.External.GetItemsInFrustum(model, planes, objectsInFrustum) || found; } var visibleLayers = Tools.visibleLayers; var items = objectsInFrustum.ToArray(); for (var i = items.Length - 1; i >= 0; i--) { var child = items[i]; var node = child.GetComponent <CSGNode>(); if (!node || ((1 << node.gameObject.layer) & visibleLayers) == 0) { continue; } if (!objectsInFrustum.Contains(child)) { continue; } while (true) { var parent = GetGroupOperationForNode(node); if (!parent || !AreAllBrushesSelected(parent.transform, objectsInFrustum)) { break; } objectsInFrustum.Add(parent.gameObject); node = parent; } } return(found); }
public static bool FindMultiWorldIntersection(Vector3 worldRayStart, Vector3 worldRayEnd, out LegacyBrushIntersection[] intersections, bool ignoreInvisibleSurfaces = true, bool ignoreUnrenderables = true, CSGBrush[] ignoreBrushes = null) { intersections = null; if (InternalCSGModelManager.External == null || InternalCSGModelManager.External.RayCastIntoModelMulti == null) { return(false); } var foundIntersections = new Dictionary <CSGNode, LegacyBrushIntersection>(); var visibleLayers = Tools.visibleLayers; ignoreInvisibleSurfaces = ignoreInvisibleSurfaces && !CSGSettings.ShowCulledSurfaces; for (var g = 0; g < InternalCSGModelManager.Models.Length; g++) { var model = InternalCSGModelManager.Models[g]; if (!ModelTraits.IsModelSelectable(model)) { continue; } if (ignoreUnrenderables && !ModelTraits.WillModelRender(model) && !Selection.Contains(model.gameObject.GetInstanceID())) { continue; } LegacyBrushIntersection[] modelIntersections; if (!InternalCSGModelManager.External.RayCastIntoModelMulti(model, worldRayStart, worldRayEnd, ignoreInvisibleSurfaces, out modelIntersections, ignoreBrushes: ignoreBrushes)) { continue; } for (var i = 0; i < modelIntersections.Length; i++) { var intersection = modelIntersections[i]; var brush = intersection.gameObject.GetComponent <CSGBrush>(); if (BrushTraits.IsSurfaceSelectable(brush, intersection.surfaceIndex)) { continue; } var currentNode = GetTopMostGroupForNode(brush); LegacyBrushIntersection other; if (foundIntersections.TryGetValue(currentNode, out other) && other.distance <= intersection.distance) { continue; } intersection.brush = brush; intersection.model = model; foundIntersections[currentNode] = modelIntersections[i]; } } if (foundIntersections.Count == 0) { return(false); } var sortedIntersections = foundIntersections.Values.ToArray(); Array.Sort(sortedIntersections, (x, y) => (int)Mathf.Sign(x.distance - y.distance)); intersections = sortedIntersections; return(true); }
public static bool FindWorldIntersection(Vector3 rayStart, Vector3 rayEnd, out LegacyBrushIntersection intersection, bool ignoreInvisibleSurfaces = true, bool ignoreUnrenderables = true, CSGBrush[] ignoreBrushes = null) { intersection = null; if (InternalCSGModelManager.External == null || InternalCSGModelManager.External.RayCastMulti == null) { return(false); } ignoreInvisibleSurfaces = ignoreInvisibleSurfaces && !CSGSettings.ShowCulledSurfaces; var visibleLayers = Tools.visibleLayers; int foundModelCount = 0; if (__foundModels.Length < InternalCSGModelManager.Models.Length) { __foundModels = new CSGModel[InternalCSGModelManager.Models.Length]; } for (var g = 0; g < InternalCSGModelManager.Models.Length; g++) { var model = InternalCSGModelManager.Models[g]; if (!ModelTraits.IsModelSelectable(model)) { continue; } if (ignoreUnrenderables && !ModelTraits.WillModelRender(model) && !Selection.Contains(model.gameObject.GetInstanceID())) { continue; } __foundModels[foundModelCount] = model; foundModelCount++; } if (foundModelCount == 0) { return(false); } LegacyBrushIntersection[] modelIntersections; if (!InternalCSGModelManager.External.RayCastMulti(foundModelCount, __foundModels, rayStart, rayEnd, ignoreInvisibleSurfaces, out modelIntersections, ignoreBrushes: ignoreBrushes)) { return(false); } for (var i = 0; i < modelIntersections.Length; i++) { var modelIntersection = modelIntersections[i]; if (intersection != null && modelIntersection.distance > intersection.distance) { continue; } var brush = modelIntersection.gameObject.GetComponent <CSGBrush>(); if (BrushTraits.IsSurfaceSelectable(brush, modelIntersection.surfaceIndex)) { continue; } modelIntersection.brush = brush; intersection = modelIntersection; } if (intersection == null) { return(false); } return(true); }
public static bool FindMultiWorldIntersection(Vector3 rayStart, Vector3 rayEnd, out BrushIntersection[] intersections, float growDistance = 0.0f, bool ignoreInvisibleSurfaces = true, bool ignoreUnrenderables = true) { intersections = null; if (InternalCSGModelManager.External == null || InternalCSGModelManager.External.RayCastIntoModelMulti == null) { return(false); } var foundIntersections = new Dictionary <CSGNode, BrushIntersection>(); ignoreInvisibleSurfaces = ignoreInvisibleSurfaces && !CSGSettings.ShowInvisibleSurfaces; for (var g = 0; g < InternalCSGModelManager.Models.Length; g++) { var model = InternalCSGModelManager.Models[g]; if (!model || !model.isActiveAndEnabled) { continue; } if (ignoreUnrenderables && !ModelTraits.WillModelRender(model) && !Selection.Contains(model.gameObject.GetInstanceID())) { continue; } BrushIntersection[] modelIntersections; var translation = model.transform.position; if (!InternalCSGModelManager.External.RayCastIntoModelMulti(model, rayStart - translation, rayEnd - translation, ignoreInvisibleSurfaces, growDistance, out modelIntersections)) { continue; } for (var i = 0; i < modelIntersections.Length; i++) { var intersection = modelIntersections[i]; CSGBrush brush = null; for (var b = 0; b < InternalCSGModelManager.Brushes.Length; b++) { if (InternalCSGModelManager.Brushes[b].brushID != intersection.brushID) { continue; } brush = InternalCSGModelManager.Brushes[b]; break; } if (BrushTraits.IsSurfaceSelectable(brush, intersection.surfaceIndex)) { continue; } intersection.brush = brush; intersection.model = model; intersection.worldIntersection += translation; intersection.plane.Translate(translation); var currentNode = GetTopMostGroupForNode(intersection.brush); BrushIntersection other; if (foundIntersections.TryGetValue(currentNode, out other) && other.distance <= intersection.distance) { continue; } foundIntersections[currentNode] = modelIntersections[i]; } } if (foundIntersections.Count == 0) { return(false); } var sortedIntersections = foundIntersections.Values.ToArray(); Array.Sort(sortedIntersections, (x, y) => (x.distance < y.distance) ? -1 : 0); intersections = sortedIntersections; return(true); }
public static bool FindWorldIntersection(Vector3 rayStart, Vector3 rayEnd, out BrushIntersection intersection, bool ignoreInvisibleSurfaces = true, bool ignoreUnrenderables = true, CSGBrush[] ignoreBrushes = null) { intersection = null; if (InternalCSGModelManager.External == null || InternalCSGModelManager.External.RayCastMulti == null) { return(false); } ignoreInvisibleSurfaces = ignoreInvisibleSurfaces && !CSGSettings.ShowCulledSurfaces; var visibleLayers = Tools.visibleLayers; List <CSGModel> models = new List <CSGModel>(); for (var g = 0; g < InternalCSGModelManager.Models.Length; g++) { var model = InternalCSGModelManager.Models[g]; if (!model || !model.isActiveAndEnabled || ((1 << model.gameObject.layer) & visibleLayers) == 0) { continue; } if (ignoreUnrenderables && !ModelTraits.WillModelRender(model) && !Selection.Contains(model.gameObject.GetInstanceID())) { continue; } models.Add(model); } BrushIntersection[] modelIntersections; if (!InternalCSGModelManager.External.RayCastMulti(models.ToArray(), rayStart, rayEnd, ignoreInvisibleSurfaces, out modelIntersections, ignoreBrushes: ignoreBrushes)) { return(false); } for (var i = 0; i < modelIntersections.Length; i++) { var modelIntersection = modelIntersections[i]; if (intersection != null && modelIntersection.distance > intersection.distance) { continue; } var brush = modelIntersection.gameObject.GetComponent <CSGBrush>(); if (BrushTraits.IsSurfaceSelectable(brush, modelIntersection.surfaceIndex)) { continue; } modelIntersection.brush = brush; intersection = modelIntersection; } if (intersection == null) { return(false); } return(true); }