コード例 #1
0
    // Start is called before the first frame update
    void Start()
    {
        /*
         * //Initialise Array
         * m_GridPoints = new GameObject[width * height * depth];
         *
         * //Instantiate grid points
         * for (int w = 0; w < width; w++)
         * {
         *  for (int h = 0; h < height; h++)
         *  {
         *      for (int d = 0; d < depth; d++)
         *      {
         *          GameObject newPoint = Instantiate(m_GridPointPrefab, transform);
         *          newPoint.transform.position = new Vector3(w, h, d);
         *          newPoint.name = string.Format("x: {0}, y: {1}, z: {2}", w, h, d);
         *          int idx = d + (h * depth) + (w * depth * height);
         *          m_GridPoints[idx] = newPoint;
         *      }
         *  }
         * }
         */


        //Determine mesh points uvw values
        float length = (m_GridPoints[1].transform.position.z - m_GridPoints[0].transform.position.z);

        m_MeshPoints_uvw = new PointUVW[m_MeshPoints.Length];
        for (int i = 0; i < m_MeshPoints.Length; i++)
        {
            GameObject[] effectiveGridPoints = FindSurroundingGridPoints(m_MeshPoints[i].transform.position);
            m_MeshPoints_uvw[i] = new PointUVW(effectiveGridPoints, m_MeshPoints[i].transform.position, length);
        }
    }
コード例 #2
0
    Vector3 GetPointPos(PointUVW point_UVW_data)
    {
        float u = point_UVW_data.u;
        float v = point_UVW_data.v;
        float w = point_UVW_data.w;

        Vector3[] vertices = point_UVW_data.GetEffectiveGridPointPositions();


        //Base point
        //horizontal points
        Vector3 x = vertices[0] + (vertices[6] - vertices[0]) * w;
        Vector3 y = vertices[1] + (vertices[7] - vertices[1]) * w;

        //vertical points
        Vector3 i = vertices[0] + (vertices[1] - vertices[0]) * u;
        Vector3 j = vertices[6] + (vertices[7] - vertices[6]) * u;

        Debug.DrawLine(x, y, Color.red);
        Debug.DrawLine(i, j, Color.blue);
        Vector3 BasePoint = x + (y - x) * u;


        //Top Point
        //horizontal points
        Vector3 a = vertices[2] + (vertices[4] - vertices[2]) * w;
        Vector3 b = vertices[3] + (vertices[5] - vertices[3]) * w;

        //vertical points
        Vector3 c = vertices[2] + (vertices[3] - vertices[2]) * u;
        Vector3 d = vertices[4] + (vertices[5] - vertices[4]) * u;

        Debug.DrawLine(a, b, Color.red);
        Debug.DrawLine(c, d, Color.blue);
        Vector3 TopPoint = a + (b - a) * u;

        Debug.DrawLine(BasePoint, TopPoint, Color.green);

        return(BasePoint + (TopPoint - BasePoint) * v);
    }