Example #1
0
        // For each brush

        // 1D:
        // Find surfaces that intersect with ray
        // Find edges on that surface, if intersection is close enough to edge, find closest point on edge
        static void FindSnapPointsAlongRay(GameObject[] selection, Vector3 worldRayStart, Vector3 worldRayDirection, List <SurfaceSnap> allSurfaceSnapEvents, List <EdgeSnap> allEdgeSnapEvents, List <VertexSnap> allVertexSnapEvents)
        {
            if (selection == null || selection.Length == 0)
            {
                return;
            }

            if (allSurfaceSnapEvents == null &&
                allEdgeSnapEvents == null &&
                allVertexSnapEvents == null)
            {
                return;
            }

            s_FoundIntersections.Clear();
            if (ChiselSceneQuery.FindFirstWorldIntersection(s_FoundIntersections, worldRayStart - worldRayDirection, worldRayStart + worldRayDirection, filter: selection))
            {
                if (allSurfaceSnapEvents != null)
                {
                    for (int i = 0; i < s_FoundIntersections.Count; i++)
                    {
                        var intersection = s_FoundIntersections[i];
                        allSurfaceSnapEvents.Add(new SurfaceSnap
                        {
                            brush        = intersection.brushIntersection.brush,
                            surfaceIndex = intersection.brushIntersection.surfaceIndex,
                            intersection = intersection.worldPlaneIntersection,
                            normal       = intersection.worldPlane.normal,
                        });
                    }
                }
            }

            if (allEdgeSnapEvents == null && allVertexSnapEvents == null)
            {
                return;
            }

            foreach (var intersection in s_FoundIntersections)
            {
                var csgBrush      = intersection.brushIntersection.brush;
                var csgTree       = intersection.brushIntersection.tree;
                var brushMeshBlob = BrushMeshManager.GetBrushMeshBlob(csgBrush.BrushMesh);
                if (!brushMeshBlob.IsCreated)
                {
                    continue;
                }

                ref var brushMesh = ref brushMeshBlob.Value;
                ref var polygons  = ref brushMesh.polygons;
Example #2
0
        static bool GetAllMaterials(CSGTreeBrush brush, CSGTreeBrush findBrush, List <ChiselBrushMaterial> brushMaterials)
        {
            if (findBrush != brush)
            {
                return(false);
            }

            var brushMeshBlob = BrushMeshManager.GetBrushMeshBlob(brush.BrushMesh.BrushMeshID);

            if (!brushMeshBlob.IsCreated)
            {
                return(true);
            }

            ref var brushMesh = ref brushMeshBlob.Value;
Example #3
0
        static bool FindSurfaceReference(ChiselNode chiselNode, CSGTreeBrush brush, CSGTreeBrush findBrush, int surfaceID, out SurfaceReference surfaceReference)
        {
            surfaceReference = null;
            if (findBrush != brush)
            {
                return(false);
            }

            var brushMeshBlob = BrushMeshManager.GetBrushMeshBlob(findBrush.BrushMesh.BrushMeshID);

            if (!brushMeshBlob.IsCreated)
            {
                return(true);
            }

            ref var brushMesh = ref brushMeshBlob.Value;
Example #4
0
        static bool GetAllSurfaces(ChiselNode chiselNode, CSGTreeBrush brush, CSGTreeBrush?findBrush, List <SurfaceReference> surfaces)
        {
            if (!brush.Valid)
            {
                return(false);
            }

            if (findBrush.HasValue && findBrush.Value != brush)
            {
                return(true);
            }

            var brushMeshBlob = BrushMeshManager.GetBrushMeshBlob(brush.BrushMesh.BrushMeshID);

            if (!brushMeshBlob.IsCreated)
            {
                return(true);
            }

            ref var brushMesh = ref brushMeshBlob.Value;