public static bool FindSurfaceIntersection(CSGBrush brush, Vector3 modelTranslation, Int32 surfaceIndex, Vector3 rayStart, Vector3 rayEnd, out BrushIntersection intersection, float growDistance = 0.0f) { intersection = null; if (!brush || InternalCSGModelManager.External.RayCastIntoBrush == null) { return(false); } var ignoreInvisible = !CSGSettings.ShowInvisibleSurfaces; if (!InternalCSGModelManager.External.RayCastIntoBrushSurface(brush.brushID, surfaceIndex, rayStart - modelTranslation, rayEnd - modelTranslation, ignoreInvisible, growDistance, out intersection)) { return(false); } if (BrushTraits.IsSurfaceSelectable(brush, intersection.surfaceIndex)) { return(false); } intersection.worldIntersection += modelTranslation; intersection.plane.Translate(modelTranslation); return(true); }
public static bool FindSurfaceIntersection(CSGBrush brush, Matrix4x4 modelTransformation, Int32 surfaceIndex, Vector3 rayStart, Vector3 rayEnd, out LegacySurfaceIntersection intersection) { intersection = null; if (!brush || InternalCSGModelManager.External.RayCastIntoBrushSurface == null) { return(false); } if (!InternalCSGModelManager.External.RayCastIntoBrushSurface(brush.brushNodeID, surfaceIndex, rayStart, rayEnd, modelTransformation, out intersection)) { return(false); } if (BrushTraits.IsSurfaceSelectable(brush, surfaceIndex)) { return(false); } return(true); }
public static bool FindSurfaceIntersection(Camera camera, CSGBrush brush, Matrix4x4 modelTransformation, Int32 surfaceIndex, Vector2 screenPos, out LegacySurfaceIntersection intersection) { var worldRay = HandleUtility.GUIPointToWorldRay(screenPos); var rayStart = worldRay.origin; var rayVector = (worldRay.direction * (camera.farClipPlane - camera.nearClipPlane)); var rayEnd = rayStart + rayVector; intersection = null; if (!brush || InternalCSGModelManager.External.RayCastIntoBrushSurface == null) { return(false); } if (!InternalCSGModelManager.External.RayCastIntoBrushSurface(brush.brushNodeID, surfaceIndex, rayStart, rayEnd, modelTransformation, out intersection)) { return(false); } if (BrushTraits.IsSurfaceUnselectable(brush, surfaceIndex, brush.ChildData.Model.IsTrigger)) { return(false); } return(true); }
public static bool FindBrushIntersection(CSGBrush brush, Vector3 modelTranslation, Vector3 rayStart, Vector3 rayEnd, out BrushIntersection intersection) { intersection = null; if (!brush || InternalCSGModelManager.External.RayCastIntoBrush == null) { return(false); } if (!InternalCSGModelManager.External.RayCastIntoBrush(brush.brushID, rayStart - modelTranslation, rayEnd - modelTranslation, out intersection, false)) { return(false); } if (BrushTraits.IsSurfaceSelectable(brush, intersection.surfaceIndex)) { return(false); } intersection.worldIntersection += modelTranslation; intersection.plane.Translate(modelTranslation); return(true); }
public static bool FindBrushIntersection(CSGBrush brush, Matrix4x4 modelTransformation, Vector3 rayStart, Vector3 rayEnd, out LegacyBrushIntersection intersection) { intersection = null; if (!brush || InternalCSGModelManager.External.RayCastIntoBrush == null) { return(false); } if (!InternalCSGModelManager.External.RayCastIntoBrush(brush.brushNodeID, rayStart, rayEnd, modelTransformation, out intersection, false)) { return(false); } if (BrushTraits.IsSurfaceUnselectable(brush, intersection.surfaceIndex, brush.ChildData.Model.IsTrigger)) { return(false); } return(true); }
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); }