Exemplo n.º 1
0
    private void OnSceneGUI()
    {
        RaycastHit hit;
        Vector2    rayPoint = new Vector2(Event.current.mousePosition.x, SceneView.currentDrawingSceneView.camera.pixelHeight - Event.current.mousePosition.y);

        if (!Physics.Raycast(SceneView.currentDrawingSceneView.camera.ScreenPointToRay(rayPoint), out hit))
        {
            return;
        }
        MeshCollider meshCollider = hit.collider as MeshCollider;

        if (meshCollider == null || meshCollider.sharedMesh == null)
        {
            return;
        }

        if (meshCollider == _meshCollider)
        {
            fillingTriangle(hit.triangleIndex);
            //_mesh.triangles[hit.triangleIndex]
            Handles.color = Color.red;
            Handles.DrawWireCube(hit.point, new Vector3(0.01f, 0.01f, 0.01f));
            List <Vector3> points = _geomProcessor.GetEdgeIntersectPoints(_transform.InverseTransformPoint(hit.point), hit.triangleIndex);
            // points[0].
            int       l  = points.Count;
            Vector3[] vp = new Vector3[l];
            for (int i = 0; i < l; i++)
            {
                vp[i] = _transform.TransformPoint(points[i]);
            }
            Handles.DrawAAPolyLine(vp);
        }
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        int i;

        for (i = 0; i < cubes.Count; i++)
        {
            cubes[i].GetComponent <Renderer>().enabled = false;
        }

        /*      Vector3 A = new Vector3(6.37312E-08f, -0.7039801f, -0.4557033f);
         *    int triN = 415;
         *    Vector3 Anew;
         *    int edgeN;
         *    _testGeomProcessor.processTriangle(triN, A, out edgeN, out Anew);
         *
         *
         *    Vector3 V01 = _vertices[_triangles[triN * 3 + 1]] - _vertices[_triangles[triN * 3 + 0]];
         *    Vector3 V02 = _vertices[_triangles[triN * 3 + 2]] - _vertices[_triangles[triN * 3 + 0]];
         *    Vector3 v0 = _vertices[_triangles[triN * 3 + 0]];
         *    Vector3 v1 = _vertices[_triangles[triN * 3 + 1]];
         *    Vector3 v2 = _vertices[_triangles[triN * 3 + 2]];
         *
         *    Vector3 n = Vector3.Cross(V01, V02);
         *    Debug.DrawRay(A, n);
         *    return;*/

        foreach (BlobGuide guide in _guides)
        {
            guide.Update();
        }


        List <Vector3> points;

        RaycastHit hit;

        //    Debug.LogError(Input.mousePosition.x+", "+ Input.mousePosition.y+", "+ Input.mousePosition.z);
        if (!Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
        {
            return;
        }
        MeshCollider meshCollider = hit.collider as MeshCollider;

        if (meshCollider == null || meshCollider.sharedMesh == null)
        {
            return;
        }

        Transform     targetObject    = null;
        GeomProcessor targetProcessor = null;

        if (meshCollider == icSpincone.GetComponent <MeshCollider>())
        {
            targetObject    = icSpincone.transform;
            targetProcessor = _testGeomProcessor_spincone;
        }
        else if (meshCollider == icSpiralLow.GetComponent <MeshCollider>())
        {
            targetObject    = icSpiralLow.transform;
            targetProcessor = _testGeomProcessor_spiralLow;
        }
        else if (meshCollider == icSpiralMid.GetComponent <MeshCollider>())
        {
            targetObject    = icSpiralMid.transform;
            targetProcessor = _testGeomProcessor_spiralMid;
        }
        else if (meshCollider == tanyaTest.GetComponent <MeshCollider>())
        {
            targetObject    = tanyaTest.transform;
            targetProcessor = _testGeomProcessor_tanyaTEst;
        }

        if (targetObject == null)
        {
            return;
        }

        points = targetProcessor.GetEdgeIntersectPoints(targetObject.InverseTransformPoint(hit.point), hit.triangleIndex);



        //points = _testGeomProcessor_testIce.GetEdgeIntersectPoints(testIce.transform.InverseTransformPoint(hit.point), hit.triangleIndex);

        /*        MeshCollider meshCollider = testIce.GetComponent<MeshCollider>();
         *      //points = _testGeomProcessor_testIce.GetEdgeIntersectPoints(testIce.transform.InverseTransformPoint(new Vector3(-0.7801354f, 0.1426054f, -0.2359176f)), 202);
         *      points = _testGeomProcessor_testIce.GetEdgeIntersectPoints(testIce.transform.InverseTransformPoint(new Vector3(-1.349147f, 0.7382534f, -0.1626387f)), 322);
         *
         *      MeshCollider meshCollider = icSpiralLow.GetComponent<MeshCollider>();
         *      points = _testGeomProcessor_spiralLow.GetEdgeIntersectPoints(icSpiralLow.transform.InverseTransformPoint(new Vector3(2.927554f, 0.9878784f, -0.008455698f)), 9092);
         */

        /*       MeshCollider meshCollider = icSpiralMid.GetComponent<MeshCollider>();
         *     //points = _testGeomProcessor_spiralMid.GetEdgeIntersectPoints(icSpiralMid.transform.InverseTransformPoint(new Vector3(1.112241f, 0.9138252f, -0.04689942f)), 15931);
         *     points = _testGeomProcessor_spiralMid.GetEdgeIntersectPoints(icSpiralMid.transform.InverseTransformPoint(new Vector3(1.002526f, 0.9781381f, -0.05147566f)), 16524);
         */
        Transform cb;

        while (points.Count > cubes.Count)
        {
            cb = Instantiate(cube, new Vector3(), Quaternion.identity);
            cb.GetComponent <Renderer>().material.color = new Color(1, 0, 0);
            cubes.Add(cb);
        }
        for (i = 0; i < points.Count; i++)
        {
            cubes[i].GetComponent <Renderer>().enabled = true;
            cubes[i].SetParent(targetObject);

            if (float.IsInfinity(points[i].x))
            {
                Debug.LogError("!!!" + meshCollider.name + ": (" + hit.point.x + "; " + hit.point.y + "; " + hit.point.z + ")|" + hit.triangleIndex);
            }
            cubes[i].transform.localPosition = points[i];
        }

        if (Input.GetMouseButtonDown(0))
        {
            Transform blob = getBlob();
            blob.SetParent(targetObject);
            BlobGuide blobGuide = new BlobGuide(blob, points);
            _guides.Add(blobGuide);
        }
    }
Exemplo n.º 3
0
 public List<Vector3> GetBlobPath(Vector3 startPoint, int startTriangle) { 
     return _geomProcessor.GetEdgeIntersectPoints(startPoint, startTriangle);
 }