コード例 #1
0
    public Vector3Obj getNextPos()
    {
        Vector3 nectPos = new Vector3();

        nectPos = pos.ToVector3() + length * dir.ToVector3();
        return(Vector3Obj.ToVector3Obj(nectPos));
    }
コード例 #2
0
    void writeUp()
    {
        for (int i = 0; i < HSpheres.Count; i++)
        {
            for (int j = 0; j < HSpheres[i].Count; j++)
            {
                Hxx.HxxUs[i][j].pos = Vector3Obj.ToVector3Obj(HSpheres[i][j].transform.position);
            }
        }
        string strSerializeJSON = JsonConvert.SerializeObject(Hxx.HxxUs);

        //Debug.Log(strSerializeJSON);
        File.WriteAllText(infoPath, strSerializeJSON);
        Debug.Log("writeUp");
    }
コード例 #3
0
    public HxxSpheres(List <Vector3> pts_, List <int> faces_, List <Vector3> vn_, List <Vector3> faceCenters_, int initialNum)
    {
        HxxUs     = new List <List <Node> >();
        facesNum_ = faces_.Count / 3;
        for (int i = 0; i < facesNum_; i++)
        {
            List <Node> theFaceU       = new List <Node>();
            Vector3     thisFaceCenter = faceCenters_[i];

            Vector3 thisNodeHead = thisFaceCenter;
            Vector3 initialDir   = vn_[i];
            for (int j = 0; j < initialNum; j++)
            {
                Node thisNode = new Node();
                thisNode.pos = Vector3Obj.ToVector3Obj(thisNodeHead);
                thisNode.setTheDir(Vector3Obj.ToVector3Obj(initialDir));
                thisNode.length = 0.08f;
                theFaceU.Add(thisNode);
                thisNodeHead = thisNode.getNextPos().ToVector3();
            }
            HxxUs.Add(theFaceU);
        }
    }
コード例 #4
0
    public void setTheDir(Vector3Obj dirInd)
    {
        var temp = dirInd.ToVector3();

        dir = Vector3Obj.ToVector3Obj(temp.normalized);
    }
コード例 #5
0
    // Update is called once per frame
    public void Update()
    {
        ;
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hit;
            Vector3    mousePos = Input.mousePosition;
            Ray        ray      = Camera.main.ScreenPointToRay(mousePos);
            if (Physics.Raycast(ray, out hit, 10000))
            {
                Debug.DrawLine(ray.origin, hit.point, Color.red);
                MeshCollider collider = hit.collider as MeshCollider;
                if (collider == null || collider.sharedMesh == null)
                {
                    theChosenFaceIdx = -1;
                    return;
                }
                Mesh      mesh0     = collider.sharedMesh;
                Vector3[] vertices  = mesh0.vertices;
                int[]     triangles = mesh0.triangles;
                theChosenFaceIdx = hit.triangleIndex;
                Vector3   p0        = hit.transform.TransformPoint(vertices[triangles[theChosenFaceIdx * 3]]);
                Vector3   p1        = hit.transform.TransformPoint(vertices[triangles[theChosenFaceIdx * 3 + 1]]);
                Vector3   p2        = hit.transform.TransformPoint(vertices[triangles[theChosenFaceIdx * 3 + 2]]);
                Transform transform = collider.transform;
                m_spheres[0].transform.position = transform.TransformPoint(p0);
                m_spheres[1].transform.position = transform.TransformPoint(p1);
                m_spheres[2].transform.position = transform.TransformPoint(p2);
                m_spheres[0].GetComponent <Renderer>().material.color = Color.blue;
                m_spheres[1].GetComponent <Renderer>().material.color = Color.green;
                m_spheres[2].GetComponent <Renderer>().material.color = Color.red;

                Debug.Log(theChosenFaceIdx);
                theChosenFaceSphereNum = HSpheres[theChosenFaceIdx].Count;
                if (theChosenFaceSphereNum < 1)
                {
                    theChosenFaceWhichSphereIdx = -1;
                }
                else
                {
                    theChosenFaceWhichSphereIdx = 0;
                }
                showUp();
            }
        }

        if (Input.GetKeyDown(KeyCode.Equals) && theChosenFaceIdx >= 0)
        {
            theChosenFaceWhichSphereIdx++;
            theChosenFaceWhichSphereIdx = theChosenFaceWhichSphereIdx % theChosenFaceSphereNum;
            Debug.Log(theChosenFaceWhichSphereIdx);
            if (theChosenFaceSphereNum < 1)
            {
                theChosenFaceWhichSphereIdx = -1;
            }
            showUp();
            Debug.Log("+");
        }
        if (Input.GetKeyDown(KeyCode.Minus) && theChosenFaceIdx >= 0)
        {
            theChosenFaceWhichSphereIdx--;
            theChosenFaceWhichSphereIdx = theChosenFaceWhichSphereIdx % theChosenFaceSphereNum;
            Debug.Log(theChosenFaceWhichSphereIdx);
            if (theChosenFaceSphereNum < 1)
            {
                theChosenFaceWhichSphereIdx = -1;
            }
            showUp();
            Debug.Log("-");
        }

        //////////////////////////////////////////////////////////////////
        if (Input.GetKeyDown(KeyCode.W) && theChosenFaceIdx >= 0 && theChosenFaceWhichSphereIdx >= 0)
        {
            Vector3 pos = HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position;
            pos.x -= inc1;
            HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position = pos;
            showUp();
        }
        if (Input.GetKeyDown(KeyCode.E) && theChosenFaceIdx >= 0 && theChosenFaceWhichSphereIdx >= 0)
        {
            Vector3 pos = HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position;
            pos.x += inc1;
            HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position = pos;
            showUp();
        }
        if (Input.GetKeyDown(KeyCode.S) && theChosenFaceIdx >= 0 && theChosenFaceWhichSphereIdx >= 0)
        {
            Vector3 pos = HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position;
            pos.y -= inc1;
            HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position = pos;
            showUp();
        }
        if (Input.GetKeyDown(KeyCode.D) && theChosenFaceIdx >= 0 && theChosenFaceWhichSphereIdx >= 0)
        {
            Vector3 pos = HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position;
            pos.y += inc1;
            HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position = pos;
            showUp();
            Debug.Log("-");
        }
        if (Input.GetKeyDown(KeyCode.X) && theChosenFaceIdx >= 0 && theChosenFaceWhichSphereIdx >= 0)
        {
            Vector3 pos = HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position;
            pos.z -= inc1;
            HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position = pos;
            showUp();
            Debug.Log("-");
        }
        if (Input.GetKeyDown(KeyCode.C) && theChosenFaceIdx >= 0 && theChosenFaceWhichSphereIdx >= 0)
        {
            Vector3 pos = HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position;
            pos.z += inc1;
            HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position = pos;
            showUp();
            Debug.Log("-");
        }
        /////////////////////////////////////////////
        if (Input.GetKeyDown(KeyCode.Q) && theChosenFaceIdx >= 0 && theChosenFaceWhichSphereIdx >= 0)
        {
            Vector3 pos = HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position;
            pos.x -= inc2;
            HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position = pos;
            showUp();
        }
        if (Input.GetKeyDown(KeyCode.R) && theChosenFaceIdx >= 0 && theChosenFaceWhichSphereIdx >= 0)
        {
            Vector3 pos = HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position;
            pos.x += inc2;
            HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position = pos;
            showUp();
        }
        if (Input.GetKeyDown(KeyCode.A) && theChosenFaceIdx >= 0 && theChosenFaceWhichSphereIdx >= 0)
        {
            Vector3 pos = HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position;
            pos.y -= inc2;
            HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position = pos;
            showUp();
        }
        if (Input.GetKeyDown(KeyCode.F) && theChosenFaceIdx >= 0 && theChosenFaceWhichSphereIdx >= 0)
        {
            Vector3 pos = HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position;
            pos.y += inc2;
            HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position = pos;
            showUp();
            Debug.Log("-");
        }
        if (Input.GetKeyDown(KeyCode.Z) && theChosenFaceIdx >= 0 && theChosenFaceWhichSphereIdx >= 0)
        {
            Vector3 pos = HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position;
            pos.z -= inc2;
            HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position = pos;
            showUp();
            Debug.Log("-");
        }
        if (Input.GetKeyDown(KeyCode.V) && theChosenFaceIdx >= 0 && theChosenFaceWhichSphereIdx >= 0)
        {
            Vector3 pos = HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position;
            pos.z += inc2;
            HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position = pos;
            showUp();
            Debug.Log("-");
        }
        ////////////////////////////////////////////////////



        if (Input.GetKeyDown(KeyCode.F1) && theChosenFaceIdx >= 0 && HSpheres[theChosenFaceIdx].Count > 1)
        {
            theChosenFaceWhichSphereIdx = 0;
            int theLastIdx   = Hxx.HxxUs[theChosenFaceIdx].Count - 1;
            var willbedelete = HSpheres[theChosenFaceIdx][theLastIdx];
            HSpheres[theChosenFaceIdx].RemoveAt(theLastIdx);
            Hxx.HxxUs[theChosenFaceIdx].RemoveAt(theLastIdx);
            Destroy(willbedelete);
            theChosenFaceSphereNum = HSpheres[theChosenFaceIdx].Count;
            showUp();
            Debug.Log("delete node");
        }
        if (Input.GetKeyDown(KeyCode.F5) && theChosenFaceIdx >= 0 && HSpheres[theChosenFaceIdx].Count > 0)
        {
            theChosenFaceWhichSphereIdx = 0;

            int     theLastIdx = Hxx.HxxUs[theChosenFaceIdx].Count - 1;
            Node    lastNode   = Hxx.HxxUs[theChosenFaceIdx][theLastIdx];
            Vector3 newNode    = lastNode.getNextPos().ToVector3();

            Node thisNode = new Node();
            thisNode.pos = Vector3Obj.ToVector3Obj(newNode);
            thisNode.setTheDir(lastNode.dir);
            thisNode.length = 0.08f;
            Hxx.HxxUs[theChosenFaceIdx].Add(thisNode);

            GameObject hs = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            hs.transform.position   = newNode;
            hs.transform.localScale = new Vector3(0.03f, 0.03f, 0.03f);
            hs.GetComponent <Renderer>().material.color = Color.white;
            HSpheres[theChosenFaceIdx].Add(hs);
            theChosenFaceSphereNum = HSpheres[theChosenFaceIdx].Count;
            showUp();
            Debug.Log("add node");
        }



        if (Input.GetKeyDown(KeyCode.L))
        {
            writeUp();
            Application.Quit();
        }

        //if (Time.frameCount % 50 == 0)
        //{
        //    writeUp();
        //}
    }