示例#1
0
        private static bool UpdateBrushMesh(Int32 brushMeshIndex,
                                            BrushMesh brushMesh)
        {
            if (brushMeshIndex == 0 ||
                brushMesh.vertices == null ||
                brushMesh.halfEdges == null ||
                brushMesh.polygons == null)
            {
                return(false);
            }

            var edgeCount = brushMesh.halfEdges.Length;

            if (edgeCount < 12)
            {
                return(false);
            }

            var polygonCount = brushMesh.polygons.Length;

            if (polygonCount < 5)
            {
                return(false);
            }

            var vertexCount = brushMesh.vertices.Length;
            var result      = UpdateBrushMesh(brushMeshIndex,
                                              vertexCount, brushMesh.vertices,
                                              edgeCount, brushMesh.halfEdges,
                                              polygonCount, brushMesh.polygons);

            return(result);
        }
示例#2
0
        private static Int32 CreateBrushMesh(int userID, BrushMesh brushMesh)
        {
            if (brushMesh == null ||
                brushMesh.vertices == null ||
                brushMesh.halfEdges == null ||
                brushMesh.polygons == null)
            {
                return(0);
            }

            var edgeCount = brushMesh.halfEdges.Length;

            if (edgeCount < 12)
            {
                return(0);
            }

            var polygonCount = brushMesh.polygons.Length;

            if (polygonCount <= 4)
            {
                return(0);
            }

            var vertexCount = brushMesh.vertices.Length;
            var result      = CreateBrushMesh(userID,
                                              vertexCount, brushMesh.vertices,
                                              edgeCount, brushMesh.halfEdges,
                                              polygonCount, brushMesh.polygons);

            if (result <= 0)
            {
                result = 0;
            }
            return(result);
        }
示例#3
0
 /// <summary>Update this <see cref="RealtimeCSG.Foundation.BrushMeshInstance"/> with the given <see cref="RealtimeCSG.Foundation.BrushMesh"/>.</summary>
 /// <param name="brushMesh">The <see cref="RealtimeCSG.Foundation.BrushMesh"/> to update the <see cref="RealtimeCSG.Foundation.BrushMeshInstance"/> with</param>
 /// <returns><b>true</b> on success, <b>false</b> on failure. In case of failure the brush will keep using the previously set <see cref="RealtimeCSG.Foundation.BrushMesh"/>.</returns>
 public bool Set(BrushMesh brushMesh)
 {
     return(UpdateBrushMesh(brushMeshID, brushMesh));
 }
示例#4
0
 /// <summary>Create a <see cref="RealtimeCSG.Foundation.BrushMeshInstance"/> from a given <see cref="RealtimeCSG.Foundation.BrushMesh"/></summary>
 /// <param name="brushMesh">The <see cref="RealtimeCSG.Foundation.BrushMesh"/> to create an instance with</param>
 /// <returns>A newly created <see cref="RealtimeCSG.Foundation.BrushMeshInstance"/> on success, or an invalid <see cref="RealtimeCSG.Foundation.BrushMeshInstance"/> on failure.</returns>
 public static BrushMeshInstance Create(BrushMesh brushMesh, Int32 userID = 0)
 {
     return(new BrushMeshInstance {
         brushMeshID = CreateBrushMesh(userID, brushMesh)
     });
 }
示例#5
0
        public static bool ValidateBrushMesh(BrushMesh brushMesh)
        {
            var vertices = brushMesh.vertices;

            if (vertices == null || vertices.Length == 0)
            {
                Debug.LogError("brushMesh has no vertices set");
                return(false);
            }

            var halfEdges = brushMesh.halfEdges;

            if (halfEdges == null || halfEdges.Length == 0)
            {
                Debug.LogError("brushMesh has no halfEdges set");
                return(false);
            }

            var polygons = brushMesh.polygons;

            if (polygons == null || polygons.Length == 0)
            {
                Debug.LogError("brushMesh has no polygons set");
                return(false);
            }

            bool fail = false;

            for (int h = 0; h < halfEdges.Length; h++)
            {
                if (halfEdges[h].vertexIndex < 0)
                {
                    Debug.LogError("brushMesh.halfEdges[" + h + "].vertexIndex is " + halfEdges[h].vertexIndex);
                    fail = true;
                }
                else
                if (halfEdges[h].vertexIndex >= vertices.Length)
                {
                    Debug.LogError("brushMesh.halfEdges[" + h + "].vertexIndex is " + halfEdges[h].vertexIndex + ", but there are " + vertices.Length + " vertices.");
                    fail = true;
                }

                if (halfEdges[h].twinIndex < 0)
                {
                    Debug.LogError("brushMesh.halfEdges[" + h + "].twinIndex is " + halfEdges[h].twinIndex);
                    fail = true;
                    continue;
                }
                else
                if (halfEdges[h].twinIndex >= halfEdges.Length)
                {
                    Debug.LogError("brushMesh.halfEdges[" + h + "].twinIndex is " + halfEdges[h].twinIndex + ", but there are " + halfEdges.Length + " edges.");
                    fail = true;
                    continue;
                }

                var twinIndex = halfEdges[h].twinIndex;
                var twin      = halfEdges[twinIndex];
                if (twin.twinIndex != h)
                {
                    Debug.LogError("brushMesh.halfEdges[" + h + "].twinIndex is " + halfEdges[h].twinIndex + ", but the twinIndex of its twin is " + twin.twinIndex + " instead of " + h + ".");
                    fail = true;
                }
            }

            for (int p = 0; p < polygons.Length; p++)
            {
                var firstEdge = polygons[p].firstEdge;
                var count     = polygons[p].edgeCount;
                if (firstEdge < 0)
                {
                    Debug.LogError("brushMesh.polygons[" + p + "].firstEdge is " + firstEdge);
                    fail = true;
                }
                else
                if (firstEdge >= halfEdges.Length)
                {
                    Debug.LogError("brushMesh.polygons[" + p + "].firstEdge is " + firstEdge + ", but there are " + halfEdges.Length + " edges.");
                    fail = true;
                }
                if (count <= 0)
                {
                    Debug.LogError("brushMesh.polygons[" + p + "].edgeCount is " + count);
                    fail = true;
                }
                else
                if (firstEdge + count > halfEdges.Length)
                {
                    Debug.LogError("brushMesh.polygons[" + p + "].firstEdge + brushMesh.polygons[" + p + "].edgeCount is " + (firstEdge + count) + ", but there are " + halfEdges.Length + " edges.");
                    fail = true;
                }
                else
                if (p < polygons.Length - 1 &&
                    polygons[p + 1].firstEdge != firstEdge + count)
                {
                    Debug.LogError("brushMesh.polygons[" + (p + 1) + "].firstEdge does not equal brushMesh.polygons[" + p + "].firstEdge + brushMesh.polygons[" + p + "].edgeCount.");
                    fail = true;
                }

                for (int i1 = 0, i0 = count - 1; i1 < count; i0 = i1, i1++)
                {
                    var h0 = halfEdges[i0 + firstEdge];                     // curr
                    var h1 = halfEdges[i1 + firstEdge];                     // curr.prev
                    var t1 = halfEdges[h1.twinIndex];                       // curr.prev.twin

                    if (h0.vertexIndex != t1.vertexIndex)
                    {
                        Debug.LogError("brushMesh.halfEdges[" + (i0 + firstEdge) + "].vertexIndex (" + h0.vertexIndex + ") is not equal to brushMesh.halfEdges[" + h1.twinIndex + "].vertexIndex (" + t1.vertexIndex + ").");
                        fail = true;
                    }
                }
            }


            return(!fail);
        }