Пример #1
0
        // TODO: turn into job
        void FindPlanePairs(IntersectionType type,
                            [NoAlias] ref BrushMeshBlob mesh,
                            [NoAlias] NativeArray <int> intersectingPlanes,
                            int intersectingPlanesLength,
                            [NoAlias] NativeArray <float4> localSpacePlanesPtr,
                            [NoAlias] ref NativeArray <int> vertexUsed,
                            float4x4 vertexTransform,
                            bool needTransform,
                            [NoAlias] ref NativeArray <PlanePair> usedPlanePairs,
                            [NoAlias] ref NativeArray <float3> usedVertices,
                            out int usedPlanePairsLength,
                            out int usedVerticesLength)
        {
            NativeCollectionHelpers.EnsureMinimumSize(ref usedVertices, mesh.localVertices.Length);
            NativeCollectionHelpers.EnsureMinimumSizeAndClear(ref usedPlanePairs, mesh.halfEdges.Length);

            if (type != IntersectionType.Intersection)
            {
                usedPlanePairsLength = 0;
                usedVerticesLength   = mesh.localVertices.Length;
                for (int i = 0; i < mesh.localVertices.Length; i++)
                {
                    usedVertices[i] = mesh.localVertices[i];
                }
                return;
            }
            NativeCollectionHelpers.EnsureMinimumSizeAndClear(ref vertexUsed, mesh.localVertices.Length);
            NativeCollectionHelpers.EnsureMinimumSizeAndClear(ref planeAvailable, mesh.localPlanes.Length);

            // TODO: this can be partially stored in brushmesh
            // TODO: optimize

            ref var halfEdgePolygonIndices = ref mesh.halfEdgePolygonIndices;
Пример #2
0
        internal void Fill(ref BrushMeshBlob brushMesh)
        {
            if (!IsCreated)
            {
                UnityEngine.Debug.LogError($"Calling Fill on uninitialized Outline");
                return;
            }
            Reset();

            ref var polygons      = ref brushMesh.polygons;
Пример #3
0
 public static int CalculateHashCode(ref BrushMeshBlob blob)
 {
     unchecked
     {
         return((int)math.hash(
                    new uint3(blob.polygons.Length == 0 ? 0 : HashExtensions.GetHashCode(blob.polygons),
                              blob.localVertices.Length == 0 ? 0 : HashExtensions.GetHashCode(blob.localVertices),
                              blob.halfEdges.Length == 0 ? 0 : HashExtensions.GetHashCode(blob.halfEdges))));
     }
 }
Пример #4
0
        public static bool UpdateBrushMesh(Int32 brushMeshInstanceID,
                                           float3[]                         vertices,
                                           BrushMesh.HalfEdge[] halfEdges,
                                           BrushMesh.Polygon[]  polygons)
        {
            if (vertices == null || halfEdges == null || polygons == null)
            {
                return(false);
            }

            if (!AssertBrushMeshIDValid(brushMeshInstanceID))
            {
                return(false);
            }

            BrushMesh brushMesh = GetBrushMesh(brushMeshInstanceID);

            if (brushMesh == null)
            {
                Debug.LogWarning("Brush has no BrushMeshInstance set");
                return(false);
            }

            if (!brushMesh.Set(vertices, halfEdges, polygons))
            {
                Debug.LogWarning("GenerateMesh failed");
                return(false);
            }

            var brushMeshIndex = brushMeshInstanceID - 1;

            if (ChiselMeshLookup.Value.brushMeshBlobs.TryGetValue(brushMeshIndex, out BlobAssetReference <BrushMeshBlob> item))
            {
                ChiselMeshLookup.Value.brushMeshBlobs.Remove(brushMeshIndex);
                if (item.IsCreated)
                {
                    item.Dispose();
                }
            }
            ChiselMeshLookup.Value.brushMeshBlobs[brushMeshIndex] = BrushMeshBlob.Build(brushMesh);
            Profiler.BeginSample("BrushMeshBlob.Build");
            CSGManager.NotifyBrushMeshModified(brushMeshInstanceID);
            Profiler.EndSample();
            return(true);
        }
Пример #5
0
        public static Int32 CreateBrushMesh(Int32 userID,
                                            float3[]                     vertices,
                                            BrushMesh.HalfEdge[] halfEdges,
                                            BrushMesh.Polygon[]  polygons)
        {
            int       brushMeshID = CreateBrushMeshID(userID);
            BrushMesh brushMesh   = GetBrushMesh(brushMeshID);

            if (brushMesh == null)
            {
                Debug.LogWarning("brushMesh == nullptr");
                DestroyBrushMesh(brushMeshID);
                return(BrushMeshInstance.InvalidInstanceID);
            }

            if (!brushMesh.Set(vertices, halfEdges, polygons))
            {
                Debug.LogWarning("GenerateMesh failed");
                DestroyBrushMesh(brushMeshID);
                return(BrushMeshInstance.InvalidInstanceID);
            }

            var brushMeshIndex = brushMeshID - 1;

            if (ChiselMeshLookup.Value.brushMeshBlobs.TryGetValue(brushMeshIndex, out BlobAssetReference <BrushMeshBlob> item))
            {
                ChiselMeshLookup.Value.brushMeshBlobs.Remove(brushMeshIndex);
                if (item.IsCreated)
                {
                    item.Dispose();
                }
            }

            Profiler.BeginSample("BrushMeshBlob.Build");
            ChiselMeshLookup.Value.brushMeshBlobs[brushMeshIndex] = BrushMeshBlob.Build(brushMesh);
            Profiler.EndSample();
            return(brushMeshID);
        }
Пример #6
0
        BlobAssetReference <BrushTreeSpacePlanes> Build(ref BrushMeshBlob brushMeshBlob, float4x4 nodeToTreeTransformation)
        {
            var nodeToTreeInverseTransposed = math.transpose(math.inverse(nodeToTreeTransformation));

            ref var localPlanes = ref brushMeshBlob.localPlanes;