コード例 #1
0
        public static List <Mesh> NVIntersect(GameObject _objectA, GameObject _objectB, CSGMeshingSettings _meshSettings)
        {
            Mesh       mesh       = _objectB.GetComponent <MeshFilter>().mesh;
            GameObject planeRight = GameObject.Instantiate(_objectB);

            planeRight.AddComponent <DestroyOnLateUpdate>();
            GameObject planeLeft = GameObject.Instantiate(_objectB);

            planeLeft.AddComponent <DestroyOnLateUpdate>();
            GameObject planeUP = GameObject.Instantiate(_objectB);

            planeUP.AddComponent <DestroyOnLateUpdate>();
            GameObject planeBack = GameObject.Instantiate(_objectB);

            planeBack.AddComponent <DestroyOnLateUpdate>();
            GameObject planeFront = GameObject.Instantiate(_objectB);

            planeFront.AddComponent <DestroyOnLateUpdate>();

            planeRight.transform.position = _objectB.transform.position + new Vector3(mesh.bounds.max.x * planeRight.transform.localScale.x, 0.0f, 0.0f);
            planeRight.transform.Rotate(new Vector3(0.0f, 0.0f, 90.0f));
            planeLeft.transform.position = _objectB.transform.position + new Vector3(mesh.bounds.min.x * planeLeft.transform.localScale.x, 0.0f, 0.0f);
            planeLeft.transform.Rotate(new Vector3(0.0f, 0.0f, -90.0f));
            planeUP.transform.position = _objectB.transform.position;
            planeUP.transform.Rotate(new Vector3(180.0f, 0.0f, 0.0f));
            planeBack.transform.position = _objectB.transform.position + new Vector3(0.0f, 0.0f, mesh.bounds.max.z * planeRight.transform.localScale.z);
            planeBack.transform.Rotate(new Vector3(-90.0f, 0.0f, 0.0f));
            planeFront.transform.position = _objectB.transform.position + new Vector3(0.0f, 0.0f, mesh.bounds.min.z * planeRight.transform.localScale.z);
            planeFront.transform.Rotate(new Vector3(90.0f, 0.0f, 0.0f));

            CSGModel modelA = new CSGModel(_objectA);
            CSGModel modelB = new CSGModel(planeRight);
            CSGModel modelC = new CSGModel(planeLeft);
            CSGModel modelD = new CSGModel(planeUP);
            CSGModel modelE = new CSGModel(planeBack);
            CSGModel modelF = new CSGModel(planeFront);

            CSGNode nodeA = new CSGNode(modelA.ToPolygons());
            CSGNode nodeB = new CSGNode(modelB.ToPolygons());
            CSGNode nodeC = new CSGNode(modelC.ToPolygons());
            CSGNode nodeD = new CSGNode(modelD.ToPolygons());
            CSGNode nodeE = new CSGNode(modelE.ToPolygons());
            CSGNode nodeF = new CSGNode(modelF.ToPolygons());

            return(CSGNode.NVIntersect(nodeA, nodeB, nodeC, nodeD, nodeE, nodeF, _meshSettings));
        }