Exemplo n.º 1
0
 private void Start()
 {
     if (this.createMultipleGrids && this.includeChildren)
     {
         this.aABCGrids = Voxelization.CreateMultipleGridsWithGameObjectMesh(base.gameObject, this.cubeSide, this.drawMeshInside);
     }
     else
     {
         this.aABCGrids = new List <Voxelization.AABCGrid>();
         Voxelization.AABCGrid item = Voxelization.CreateGridWithGameObjectMesh(base.gameObject, this.cubeSide, this.includeChildren, this.drawMeshInside);
         this.aABCGrids.Add(item);
     }
 }
Exemplo n.º 2
0
            protected bool TriangleIntersectAABCUnchecked(Vector3[] triangle, int x, int y, int z)
            {
                Vector3 rhs     = new Vector3(1f, 0f, 0f);
                Vector3 vector6 = new Vector3(0f, 1f, 0f);
                Vector3 vector7 = new Vector3(0f, 0f, 1f);

                Vector3[] solidA  = this.GetAABCCornersUnchecked(x, y, z);
                Vector3   lhs     = triangle[1] - triangle[0];
                Vector3   vector2 = triangle[2] - triangle[1];
                Vector3   vector3 = triangle[0] - triangle[2];

                if (!Voxelization.ProjectionsIntersectOnAxis(solidA, triangle, Vector3.Cross(lhs, rhs)))
                {
                    return(false);
                }
                if (!Voxelization.ProjectionsIntersectOnAxis(solidA, triangle, Vector3.Cross(lhs, vector6)))
                {
                    return(false);
                }
                if (!Voxelization.ProjectionsIntersectOnAxis(solidA, triangle, Vector3.Cross(lhs, vector7)))
                {
                    return(false);
                }
                if (!Voxelization.ProjectionsIntersectOnAxis(solidA, triangle, Vector3.Cross(vector2, rhs)))
                {
                    return(false);
                }
                if (!Voxelization.ProjectionsIntersectOnAxis(solidA, triangle, Vector3.Cross(vector2, vector6)))
                {
                    return(false);
                }
                if (!Voxelization.ProjectionsIntersectOnAxis(solidA, triangle, Vector3.Cross(vector2, vector7)))
                {
                    return(false);
                }
                if (!Voxelization.ProjectionsIntersectOnAxis(solidA, triangle, Vector3.Cross(vector3, rhs)))
                {
                    return(false);
                }
                if (!Voxelization.ProjectionsIntersectOnAxis(solidA, triangle, Vector3.Cross(vector3, vector6)))
                {
                    return(false);
                }
                if (!Voxelization.ProjectionsIntersectOnAxis(solidA, triangle, Vector3.Cross(vector3, vector7)))
                {
                    return(false);
                }
                Vector3 axis = Vector3.Cross(lhs, vector2);

                if (!Voxelization.ProjectionsIntersectOnAxis(solidA, triangle, axis))
                {
                    return(false);
                }
                if (!Voxelization.ProjectionsIntersectOnAxis(solidA, triangle, rhs))
                {
                    return(false);
                }
                if (!Voxelization.ProjectionsIntersectOnAxis(solidA, triangle, vector6))
                {
                    return(false);
                }
                if (!Voxelization.ProjectionsIntersectOnAxis(solidA, triangle, vector7))
                {
                    return(false);
                }
                return(true);
            }
Exemplo n.º 3
0
            public void FillGridWithGameObjectMeshShell(GameObject gameObj, bool storeNormalSum)
            {
                Mesh      mesh      = gameObj.GetComponent <MeshFilter>().mesh;
                Transform transform = gameObj.transform;

                Vector3[] triangle             = new Vector3[3];
                float     realtimeSinceStartup = Time.realtimeSinceStartup;

                Vector3[] vertices  = mesh.vertices;
                int[]     triangles = mesh.triangles;
                int       num2      = triangles.Length / 3;
                int       num6      = 0;

                if (storeNormalSum)
                {
                    this.cubeNormalSum = new int[this.width, this.height, this.depth];
                }
                if (this.debug)
                {
                    Debug.Log("Start:");
                    Debug.Log("Time: " + realtimeSinceStartup);
                    Debug.Log("\t\tMesh Description: ");
                    Debug.Log("Name: " + mesh.name);
                    Debug.Log("Triangles: " + num2);
                    Debug.Log("Local AABB size: " + mesh.bounds.size);
                    Debug.Log("\t\tAABCGrid Description:");
                    Debug.Log(string.Concat(new object[] { "Size: ", this.width, ',', this.height, ',', this.depth }));
                }
                for (int i = 0; i < num2; i++)
                {
                    int num3;
                    int num4;
                    int num5;
                    triangle[0] = transform.TransformPoint(vertices[triangles[i * 3]]);
                    triangle[1] = transform.TransformPoint(vertices[triangles[(i * 3) + 1]]);
                    triangle[2] = transform.TransformPoint(vertices[triangles[(i * 3) + 2]]);
                    float num8  = Mathf.Floor((Mathf.Min(new float[] { triangle[0].x, triangle[1].x, triangle[2].x }) - this.origin.x) / this.side);
                    float num9  = Mathf.Floor((Mathf.Min(new float[] { triangle[0].y, triangle[1].y, triangle[2].y }) - this.origin.y) / this.side);
                    float num10 = Mathf.Floor((Mathf.Min(new float[] { triangle[0].z, triangle[1].z, triangle[2].z }) - this.origin.z) / this.side);
                    float num11 = Mathf.Ceil((Mathf.Max(new float[] { triangle[0].x, triangle[1].x, triangle[2].x }) - this.origin.x) / this.side);
                    float num12 = Mathf.Ceil((Mathf.Max(new float[] { triangle[0].y, triangle[1].y, triangle[2].y }) - this.origin.y) / this.side);
                    float num13 = Mathf.Ceil((Mathf.Max(new float[] { triangle[0].z, triangle[1].z, triangle[2].z }) - this.origin.z) / this.side);
                    if (storeNormalSum)
                    {
                        num3 = (int)num8;
                        while (num3 <= num11)
                        {
                            num4 = (int)num9;
                            while (num4 <= num12)
                            {
                                num5 = (int)num10;
                                while (num5 <= num13)
                                {
                                    if (this.TriangleIntersectAABC(triangle, num3, num4, num5))
                                    {
                                        Vector3 triangleNormal = Voxelization.GetTriangleNormal(triangle);
                                        this.cubeSet[num3, num4, num5] = true;
                                        if (triangleNormal.z < -num6)
                                        {
                                            this.cubeNormalSum[num3, num4, num5]++;
                                        }
                                        else if (triangleNormal.z > num6)
                                        {
                                            this.cubeNormalSum[num3, num4, num5]--;
                                        }
                                    }
                                    num5++;
                                }
                                num4++;
                            }
                            num3++;
                        }
                    }
                    else
                    {
                        for (num3 = (int)num8; num3 < num11; num3++)
                        {
                            for (num4 = (int)num9; num4 < num12; num4++)
                            {
                                for (num5 = (int)num10; num5 < num13; num5++)
                                {
                                    if (!this.IsAABCSet(num3, num4, num5) && this.TriangleIntersectAABC(triangle, num3, num4, num5))
                                    {
                                        this.cubeSet[num3, num4, num5] = true;
                                    }
                                }
                            }
                        }
                    }
                }
                if (this.debug)
                {
                    Debug.Log("Grid Evaluation Ended!");
                    Debug.Log("Time spent: " + (Time.realtimeSinceStartup - realtimeSinceStartup) + "s");
                    Debug.Log("End: ");
                }
            }