Exemple #1
0
 private static Int32 CreateBrushMesh(Int32 userID,
                                      Vector3[]                          vertices,
                                      BrushMesh.HalfEdge[]       halfEdges,
                                      BrushMesh.Polygon[]        polygons)
 {
     return(BrushMeshManager.CreateBrushMesh(userID, vertices, halfEdges, polygons));
 }
Exemple #2
0
 private static bool UpdateBrushMesh(Int32 brushMeshID,
                                     Vector3[]            vertices,
                                     BrushMesh.HalfEdge[] halfEdges,
                                     BrushMesh.Polygon[]  polygons)
 {
     return(BrushMeshManager.UpdateBrushMesh(brushMeshID, vertices, halfEdges, polygons));
 }
Exemple #3
0
        internal static void GenerateSurfaceRenderBuffers(int brushNodeID, LoopList loopList)
        {
            var output        = CSGManager.GetBrushOutput(brushNodeID);
            var brushInstance = CSGManager.GetBrushMeshID(brushNodeID);
            var mesh          = BrushMeshManager.GetBrushMesh(brushInstance);
            var meshPolygons  = mesh.polygons;
            var meshSurfaces  = mesh.surfaces;

            Matrix4x4 worldToLocal = Matrix4x4.identity;

            CSGManager.GetTreeToNodeSpaceMatrix(brushNodeID, out worldToLocal);

            var outputSurfaces     = new CSGSurfaceRenderBuffer[loopList.loops.Count]; // TODO: should be same size as brush.surfaces.Length
            int outputSurfaceCount = 0;

            foreach (var loop in loopList.loops)
            {
                var polygonIndex = loop.basePlaneIndex;       // TODO: fix this
                var meshPolygon  = meshPolygons[polygonIndex];

                var surfaceIndex = meshPolygon.surfaceID;       // TODO: fix this

                var localSpaceToPlaneSpace = MathExtensions.GenerateLocalToPlaneSpaceMatrix(meshSurfaces[surfaceIndex].plane);
                var uv0Matrix = meshPolygon.description.UV0.ToMatrix() * (localSpaceToPlaneSpace * worldToLocal);

                // TODO: all separate loops on same surface should be put in same OutputSurfaceMesh
                if (!loop.Triangulate(uv0Matrix, ref outputSurfaces[outputSurfaceCount]))
                {
                    continue;
                }

                // TODO: make this work
//				outputSurfaces[outputSurfaceCount].meshQuery		= loop.layers; //???
//				outputSurfaces[outputSurfaceCount].surfaceParameter = loop.surfaceParameter; //???
                outputSurfaces[outputSurfaceCount].surfaceIndex = surfaceIndex;
                outputSurfaceCount++;
            }
            if (outputSurfaceCount != loopList.loops.Count)
            {
                Array.Resize(ref outputSurfaces, outputSurfaceCount);
            }
            output.renderBuffers.surfaceRenderBuffers.AddRange(outputSurfaces);
        }
        internal static void UpdateOutline(Int32 brushNodeID)
        {
            var brushInfo           = CSGManager.GetBrushInfo(brushNodeID);
            var brushMeshInstanceID = CSGManager.GetBrushMeshID(brushNodeID);

            if (BrushMeshManager.IsBrushMeshIDValid(brushMeshInstanceID))
            {
                var brushMesh = BrushMeshManager.GetBrushMesh(brushMeshInstanceID);
                brushInfo.brushOutline = CreateOutline(brushMesh);
            }
            else
            {
                if (brushInfo.brushOutline == null)
                {
                    brushInfo.brushOutline = new BrushOutline();
                }
                brushInfo.brushOutline.Reset();
            }
        }
Exemple #5
0
 private static bool IsBrushMeshIDValid(Int32 brushMeshID)
 {
     return(BrushMeshManager.IsBrushMeshIDValid(brushMeshID));
 }
Exemple #6
0
 private static bool DestroyBrushMesh(Int32 brushMeshID)
 {
     return(BrushMeshManager.DestroyBrushMesh(brushMeshID));
 }
Exemple #7
0
 private static Int32 GetBrushMeshUserID(Int32 brushMeshIndex)
 {
     return(BrushMeshManager.GetBrushMeshUserID(brushMeshIndex));
 }
Exemple #8
0
        // TODO: not really CSG yet .. just a hack
        // TODO: move somewhere else
        internal static LoopList PerformCSG(int brushNodeID, bool mode)
        {
            var brushNodeIndex = brushNodeID - 1;
            var output         = CSGManager.GetBrushOutput(brushNodeID);
            var outputLoops    = output.brushOutputLoops;
            var brushInstance  = CSGManager.GetBrushMeshID(brushNodeID);
            var surfaceLoops   = (outputLoops.intersectionLoops == null || outputLoops.intersectionLoops.Count == 0) ? null : outputLoops.intersectionLoops.Values.First();  // temp. Hack

            // TODO: get rid of needing mesh here
            var mesh         = BrushMeshManager.GetBrushMesh(brushInstance);
            var meshPolygons = mesh.polygons;
            var meshSurfaces = mesh.surfaces;


            var loopList = new LoopList(); // TODO: get rid of this somehow

            // TODO: separate base loops with holes
            //          need a seperate set of holes per intersecting brush
            for (int p = 0; p < meshPolygons.Length; p++)
            {
                // TODO: get rid of needing mesh here
                var meshPolygon  = meshPolygons[p];
                var surfaceIndex = meshPolygon.surfaceID;


                // Add all holes that share the same plane to the polygon
                var holeLoops = (surfaceLoops == null) ? (List <Loop>)null : surfaceLoops.surfaces[surfaceIndex];
                // Add all holes that share the same plane to the polygon
                if (mode)
                {
                    var loop = outputLoops.basePolygons[p]; // TODO: need to copy this
                    loopList.loops.Add(loop);
                    if (holeLoops != null)
                    {
                        for (int l = holeLoops.Count - 1; l >= 0; l--)
                        {
                            //if (holeLoops[l].basePlaneIndex != loop.basePlaneIndex)
                            //	continue;

                            // Cut polygons with its holes if they overlap
                            if (loopList.RemoveFrom(loop, holeLoops[l]))
                            {
                                holeLoops.RemoveAt(l);
                                //	lookHierarchies.Add(holeLoops[l]);
                                continue;
                            }
                            //loop.holes.Add(holeLoops[l]);
                        }
                        loop.holes.AddRange(holeLoops);
                    }
                }
                else
                {
                    if (holeLoops != null)
                    {
                        foreach (var hole in holeLoops)
                        {
                            hole.interiorCategory = Category.ReverseAligned;
                            loopList.loops.Add(hole);
                        }
                    }
                }
            }
            return(loopList);
        }