private void SavePointsAngle(EventParam param)
 {
     pointsAngle.WriteLine(param.getStringParam());
 }
 private void SavePlaneDistance(EventParam param)
 {
     planeDistance.WriteLine(param.getStringParam());
 }
 void UpdateMeasureMode(EventParam nameParam)
 {
     currentActiveMeasure = nameParam.getStringParam();
 }
Exemplo n.º 4
0
    void DisplayResult(EventParam param)
    {
        if (resultCanvas.activeSelf == false || resultCanvas.transform.GetChild(0).GetChild(0).GetComponent <Text>().text != param.getStringParam())
        {
            // set result canvas transform
            resultCanvas.transform.SetParent(previousHand.transform);
            resultCanvas.transform.localPosition = interfacePosition + Vector3.up * 0.01f;
            resultCanvas.transform.localRotation = interfaceRotation;
            // set canvas text
            resultCanvas.transform.GetChild(0).GetChild(0).GetComponent <Text>().text = param.getStringParam();

            resultCanvas.SetActive(true);
        }
        else if (resultCanvas.transform.GetChild(0).GetChild(0).GetComponent <Text>().text == param.getStringParam())
        {
            resultCanvas.SetActive(false);
        }
    }
Exemplo n.º 5
0
    // main method
    public void LoadMesh(EventParam pathParam)
    {
        // file and texture files path to load
        string[] pathSplited = pathParam.getStringParam().Trim().Split('.'); // keep the file path apart from its extention
        _path    = pathSplited[0] + ".obj";                                  // fetch the .obj file
        _texPath = pathSplited[0] + ".jpg";                                  // fetch the corresponding .jpg file

        // text lists for file parsing
        _verts  = new List <string>();
        _norms  = new List <string>();
        _tex    = new List <string>();
        _facets = new List <string>();

        xmin = 0;
        xmax = 0;
        ymin = 0;
        ymax = 0;
        zmin = 0;
        zmax = 0;

        // number of subdivisions
        _subdivision     = 20;
        _subdivisionVert = 4;
        int meshnumber = _subdivision * _subdivision * _subdivisionVert;


        // lists initialisation
        _dicoVertexUVs     = new List <Dictionary <string, HashSet <string> > >();
        _dicoIndexes       = new List <Dictionary <string, int> >();
        _vertexArrayList   = new List <List <Vector3> >();
        _uvArrayList       = new List <List <Vector2> >();
        _triangleArrayList = new List <List <int> >();
        for (int i = 0; i < meshnumber; i++)
        {
            _dicoVertexUVs.Add(new Dictionary <string, HashSet <string> >());
            _dicoIndexes.Add(new Dictionary <string, int>());
            _vertexArrayList.Add(new List <Vector3>());
            _uvArrayList.Add(new List <Vector2>());
            _triangleArrayList.Add(new List <int>());
        }


        // file parsing
        if (!File.Exists(_path))
        {
            Debug.Log("fichier innexistant");
        }
        else
        {
            _file = File.OpenRead(_path);

            // file reading
            foreach (string _line in File.ReadLines(_path))
            {
                string[] text = _line.Trim().Split(' ');

                // put line in the right list
                switch (text[0])
                {
                case "v":
                    // bounds calculation
                    _vertexCoordinates = new Vector3(float.Parse(text[1], CultureInfo.InvariantCulture), float.Parse(text[2], CultureInfo.InvariantCulture), float.Parse(text[3], CultureInfo.InvariantCulture));
                    if (_vertexCoordinates.x < xmin)
                    {
                        xmin = _vertexCoordinates.x;
                    }
                    else if (_vertexCoordinates.x > xmax)
                    {
                        xmax = _vertexCoordinates.x;
                    }
                    if (_vertexCoordinates.y < ymin)
                    {
                        ymin = _vertexCoordinates.y;
                    }
                    else if (_vertexCoordinates.y > ymax)
                    {
                        ymax = _vertexCoordinates.y;
                    }
                    if (_vertexCoordinates.z < zmin)
                    {
                        zmin = _vertexCoordinates.z;
                    }
                    else if (_vertexCoordinates.z > zmax)
                    {
                        zmax = _vertexCoordinates.z;
                    }

                    _verts.Add(text[1] + ' ' + text[2] + ' ' + text[3]);
                    break;

                case "vt":
                    _tex.Add(text[1] + ' ' + text[2]);
                    break;

                case "vn":
                    _norms.Add(text[1] + ' ' + text[2] + ' ' + text[3]);
                    break;

                case "f":
                    _facets.Add(text[1] + ' ' + text[2] + ' ' + text[3]);
                    break;

                default:
                    break;
                }
            }

            // calculate mesh center
            _meshCenter = new Vector3((xmin + xmax) / 2, (ymin + ymax) / 2, (zmin + zmax) / 2);

            // facet processing
            string[] _fLine;
            int      _facetIndex;
            for (_facetIndex = 0; _facetIndex < _facets.Count; _facetIndex++)
            {
                _fLine = _facets[_facetIndex].Trim().Split(' '); // line format: "v1/vt1/vn1 v2/vt2/vn2 v3/vt3/vn3"

                string[] s1 = _fLine[0].Trim().Split('/');
                string[] s2 = _fLine[1].Trim().Split('/');
                string[] s3 = _fLine[2].Trim().Split('/');

                // store the indexes of facet's vertices
                // -1 to all indexes because .obj format starts index from 1 instead of 0
                List <Vector3Int> f = new List <Vector3Int>();
                f.Add(new Vector3Int(Int32.Parse(s1[0]) - 1, Int32.Parse(s1[1]) - 1, Int32.Parse(s1[2]) - 1)); // 1st vertex [v, vt, vn]
                f.Add(new Vector3Int(Int32.Parse(s2[0]) - 1, Int32.Parse(s2[1]) - 1, Int32.Parse(s2[2]) - 1)); // 2nd vertex [v, vt, vn]
                f.Add(new Vector3Int(Int32.Parse(s3[0]) - 1, Int32.Parse(s3[1]) - 1, Int32.Parse(s3[2]) - 1)); // 3rd vertex [v, vt, vn]

                // variables pour parser
                string[]       _res;
                List <Vector3> coordSommets = new List <Vector3>();
                List <Vector2> coordTexture = new List <Vector2>();

                _res = _verts[f[0].x].Trim().Split(' ');
                coordSommets.Add(new Vector3(float.Parse(_res[0], CultureInfo.InvariantCulture), float.Parse(_res[1], CultureInfo.InvariantCulture), float.Parse(_res[2], CultureInfo.InvariantCulture)));
                _res = _verts[f[1].x].Trim().Split(' ');
                coordSommets.Add(new Vector3(float.Parse(_res[0], CultureInfo.InvariantCulture), float.Parse(_res[1], CultureInfo.InvariantCulture), float.Parse(_res[2], CultureInfo.InvariantCulture)));
                _res = _verts[f[2].x].Trim().Split(' ');
                coordSommets.Add(new Vector3(float.Parse(_res[0], CultureInfo.InvariantCulture), float.Parse(_res[1], CultureInfo.InvariantCulture), float.Parse(_res[2], CultureInfo.InvariantCulture)));

                // calculate facet center to set it to the proper submesh
                _vertexCoordinates = (coordSommets[0] + coordSommets[1] + coordSommets[2]) / 3;

                _res = _tex[f[0].y].Trim().Split(' ');
                coordTexture.Add(new Vector2(float.Parse(_res[0], CultureInfo.InvariantCulture), float.Parse(_res[1], CultureInfo.InvariantCulture)));
                _res = _tex[f[1].y].Trim().Split(' ');
                coordTexture.Add(new Vector2(float.Parse(_res[0], CultureInfo.InvariantCulture), float.Parse(_res[1], CultureInfo.InvariantCulture)));
                _res = _tex[f[2].y].Trim().Split(' ');
                coordTexture.Add(new Vector2(float.Parse(_res[0], CultureInfo.InvariantCulture), float.Parse(_res[1], CultureInfo.InvariantCulture)));

                int facetSubMeshIndex = 0;

                // set submesh index according to its x position
                if (_vertexCoordinates.x < (xmin + xmax) / 20)
                {
                    facetSubMeshIndex += 0;
                }
                else if ((_vertexCoordinates.x >= (xmin + xmax) / 20) && (_vertexCoordinates.x < ((xmin + xmax) * 2) / 20))
                {
                    facetSubMeshIndex += 1;
                }
                else if ((_vertexCoordinates.x >= ((xmin + xmax) * 2) / 20) && (_vertexCoordinates.x < ((xmin + xmax) * 3) / 20))
                {
                    facetSubMeshIndex += 2;
                }
                else if ((_vertexCoordinates.x >= ((xmin + xmax) * 3) / 20) && (_vertexCoordinates.x < ((xmin + xmax) * 4) / 20))
                {
                    facetSubMeshIndex += 3;
                }
                else if ((_vertexCoordinates.x >= ((xmin + xmax) * 4) / 20) && (_vertexCoordinates.x < ((xmin + xmax) * 5) / 20))
                {
                    facetSubMeshIndex += 4;
                }
                else if ((_vertexCoordinates.x >= ((xmin + xmax) * 5) / 20) && (_vertexCoordinates.x < ((xmin + xmax) * 6) / 20))
                {
                    facetSubMeshIndex += 5;
                }
                else if ((_vertexCoordinates.x >= ((xmin + xmax) * 6) / 20) && (_vertexCoordinates.x < ((xmin + xmax) * 7) / 20))
                {
                    facetSubMeshIndex += 6;
                }
                else if ((_vertexCoordinates.x >= ((xmin + xmax) * 7) / 20) && (_vertexCoordinates.x < ((xmin + xmax) * 8) / 20))
                {
                    facetSubMeshIndex += 7;
                }
                else if ((_vertexCoordinates.x >= ((xmin + xmax) * 8) / 20) && (_vertexCoordinates.x < ((xmin + xmax) * 9) / 20))
                {
                    facetSubMeshIndex += 8;
                }
                else if ((_vertexCoordinates.x >= ((xmin + xmax) * 9) / 20) && (_vertexCoordinates.x < ((xmin + xmax) * 10) / 20))
                {
                    facetSubMeshIndex += 9;
                }
                else if ((_vertexCoordinates.x >= ((xmin + xmax) * 10) / 20) && (_vertexCoordinates.x < ((xmin + xmax) * 11) / 20))
                {
                    facetSubMeshIndex += 10;
                }
                else if ((_vertexCoordinates.x >= ((xmin + xmax) * 11) / 20) && (_vertexCoordinates.x < ((xmin + xmax) * 12) / 20))
                {
                    facetSubMeshIndex += 11;
                }
                else if ((_vertexCoordinates.x >= ((xmin + xmax) * 12) / 20) && (_vertexCoordinates.x < ((xmin + xmax) * 13) / 20))
                {
                    facetSubMeshIndex += 12;
                }
                else if ((_vertexCoordinates.x >= ((xmin + xmax) * 13) / 20) && (_vertexCoordinates.x < ((xmin + xmax) * 14) / 20))
                {
                    facetSubMeshIndex += 13;
                }
                else if ((_vertexCoordinates.x >= ((xmin + xmax) * 14) / 20) && (_vertexCoordinates.x < ((xmin + xmax) * 15) / 20))
                {
                    facetSubMeshIndex += 14;
                }
                else if ((_vertexCoordinates.x >= ((xmin + xmax) * 15) / 20) && (_vertexCoordinates.x < ((xmin + xmax) * 16) / 20))
                {
                    facetSubMeshIndex += 15;
                }
                else if ((_vertexCoordinates.x >= ((xmin + xmax) * 16) / 20) && (_vertexCoordinates.x < ((xmin + xmax) * 17) / 20))
                {
                    facetSubMeshIndex += 16;
                }
                else if ((_vertexCoordinates.x >= ((xmin + xmax) * 17) / 20) && (_vertexCoordinates.x < ((xmin + xmax) * 18) / 20))
                {
                    facetSubMeshIndex += 17;
                }
                else if ((_vertexCoordinates.x >= ((xmin + xmax) * 18) / 20) && (_vertexCoordinates.x < ((xmin + xmax) * 19) / 20))
                {
                    facetSubMeshIndex += 18;
                }
                else if ((_vertexCoordinates.x >= ((xmin + xmax) * 19) / 20))
                {
                    facetSubMeshIndex += 19;
                }

                // set submesh index according to its z position
                if (_vertexCoordinates.z < (zmin + zmax) / 20)
                {
                    facetSubMeshIndex += 0;
                }
                else if ((_vertexCoordinates.z >= (zmin + zmax) / 20) && (_vertexCoordinates.z < ((zmin + zmax) * 2) / 20))
                {
                    facetSubMeshIndex += 1 * _subdivision;
                }
                else if ((_vertexCoordinates.z >= ((zmin + zmax) * 2) / 20) && (_vertexCoordinates.z < ((zmin + zmax) * 3) / 20))
                {
                    facetSubMeshIndex += 2 * _subdivision;
                }
                else if ((_vertexCoordinates.z >= ((zmin + zmax) * 3) / 20) && (_vertexCoordinates.z < ((zmin + zmax) * 4) / 20))
                {
                    facetSubMeshIndex += 3 * _subdivision;
                }
                else if ((_vertexCoordinates.z >= ((zmin + zmax) * 4) / 20) && (_vertexCoordinates.z < ((zmin + zmax) * 5) / 20))
                {
                    facetSubMeshIndex += 4 * _subdivision;
                }
                else if ((_vertexCoordinates.z >= ((zmin + zmax) * 5) / 20) && (_vertexCoordinates.z < ((zmin + zmax) * 6) / 20))
                {
                    facetSubMeshIndex += 5 * _subdivision;
                }
                else if ((_vertexCoordinates.z >= ((zmin + zmax) * 6) / 20) && (_vertexCoordinates.z < ((zmin + zmax) * 7) / 20))
                {
                    facetSubMeshIndex += 6 * _subdivision;
                }
                else if ((_vertexCoordinates.z >= ((zmin + zmax) * 7) / 20) && (_vertexCoordinates.z < ((zmin + zmax) * 8) / 20))
                {
                    facetSubMeshIndex += 7 * _subdivision;
                }
                else if ((_vertexCoordinates.z >= ((zmin + zmax) * 8) / 20) && (_vertexCoordinates.z < ((zmin + zmax) * 9) / 20))
                {
                    facetSubMeshIndex += 8 * _subdivision;
                }
                else if ((_vertexCoordinates.z >= ((zmin + zmax) * 9) / 20) && (_vertexCoordinates.z < ((zmin + zmax) * 10) / 20))
                {
                    facetSubMeshIndex += 9 * _subdivision;
                }
                else if ((_vertexCoordinates.z >= ((zmin + zmax) * 10) / 20) && (_vertexCoordinates.z < ((zmin + zmax) * 11) / 20))
                {
                    facetSubMeshIndex += 10 * _subdivision;
                }
                else if ((_vertexCoordinates.z >= ((zmin + zmax) * 11) / 20) && (_vertexCoordinates.z < ((zmin + zmax) * 12) / 20))
                {
                    facetSubMeshIndex += 11 * _subdivision;
                }
                else if ((_vertexCoordinates.z >= ((zmin + zmax) * 12) / 20) && (_vertexCoordinates.z < ((zmin + zmax) * 13) / 20))
                {
                    facetSubMeshIndex += 12 * _subdivision;
                }
                else if ((_vertexCoordinates.z >= ((zmin + zmax) * 13) / 20) && (_vertexCoordinates.z < ((zmin + zmax) * 14) / 20))
                {
                    facetSubMeshIndex += 13 * _subdivision;
                }
                else if ((_vertexCoordinates.z >= ((zmin + zmax) * 14) / 20) && (_vertexCoordinates.z < ((zmin + zmax) * 15) / 20))
                {
                    facetSubMeshIndex += 14 * _subdivision;
                }
                else if ((_vertexCoordinates.z >= ((zmin + zmax) * 15) / 20) && (_vertexCoordinates.z < ((zmin + zmax) * 16) / 20))
                {
                    facetSubMeshIndex += 15 * _subdivision;
                }
                else if ((_vertexCoordinates.z >= ((zmin + zmax) * 16) / 20) && (_vertexCoordinates.z < ((zmin + zmax) * 17) / 20))
                {
                    facetSubMeshIndex += 16 * _subdivision;
                }
                else if ((_vertexCoordinates.z >= ((zmin + zmax) * 17) / 20) && (_vertexCoordinates.z < ((zmin + zmax) * 18) / 20))
                {
                    facetSubMeshIndex += 17 * _subdivision;
                }
                else if ((_vertexCoordinates.z >= ((zmin + zmax) * 18) / 20) && (_vertexCoordinates.z < ((zmin + zmax) * 19) / 20))
                {
                    facetSubMeshIndex += 18 * _subdivision;
                }
                else if ((_vertexCoordinates.z >= ((zmin + zmax) * 19) / 20))
                {
                    facetSubMeshIndex += 19 * _subdivision;
                }

                // set submesh index according to its y position (vertical)
                if (_vertexCoordinates.y < (ymin + ymax) / 4)
                {
                    facetSubMeshIndex += 0 * _subdivision * _subdivision;
                }
                else if ((_vertexCoordinates.y >= (ymin + ymax) / 4) && (_vertexCoordinates.y < ((ymin + ymax) * 2) / 4))
                {
                    facetSubMeshIndex += 1 * _subdivision * _subdivision;
                }
                else if ((_vertexCoordinates.y >= ((ymin + ymax) * 2) / 4) && (_vertexCoordinates.y < ((ymin + ymax) * 3) / 4))
                {
                    facetSubMeshIndex += 2 * _subdivision * _subdivision;
                }

                /*
                 * else if ((_vertexCoordinates.y >= ((ymin + ymax) * 3) / 10) && (_vertexCoordinates.y < ((ymin + ymax) * 4) / 10))
                 * {
                 *  facetSubMeshIndex += 3 * _subdivision * _subdivision;
                 * }
                 * else if ((_vertexCoordinates.y >= ((ymin + ymax) * 4) / 10) && (_vertexCoordinates.y < ((ymin + ymax) * 5) / 10))
                 * {
                 *  facetSubMeshIndex += 4 * _subdivision * _subdivision;
                 * }
                 * else if ((_vertexCoordinates.y >= ((ymin + ymax) * 5) / 10) && (_vertexCoordinates.y < ((ymin + ymax) * 6) / 10))
                 * {
                 *  facetSubMeshIndex += 5 * _subdivision * _subdivision;
                 * }
                 * else if ((_vertexCoordinates.y >= ((ymin + ymax) * 6) / 10) && (_vertexCoordinates.y < ((ymin + ymax) * 7) / 10))
                 * {
                 *  facetSubMeshIndex += 6 * _subdivision * _subdivision;
                 * }
                 * else if ((_vertexCoordinates.y >= ((ymin + ymax) * 7) / 10) && (_vertexCoordinates.y < ((ymin + ymax) * 8) / 10))
                 * {
                 *  facetSubMeshIndex += 7 * _subdivision * _subdivision;
                 * }
                 * else if ((_vertexCoordinates.y >= ((ymin + ymax) * 8) / 10) && (_vertexCoordinates.y < ((ymin + ymax) * 9) / 10))
                 * {
                 *  facetSubMeshIndex += 8 * _subdivision * _subdivision;
                 * }*/
                else if ((_vertexCoordinates.y >= ((ymin + ymax) * 3) / 4))
                {
                    facetSubMeshIndex += 3 * _subdivision * _subdivision;
                }

                // use quadtree structure to improve ?

                // fill the proper submesh
                StoreInMesh(_dicoVertexUVs[facetSubMeshIndex], _dicoIndexes[facetSubMeshIndex], _vertexArrayList[facetSubMeshIndex], _uvArrayList[facetSubMeshIndex], _triangleArrayList[facetSubMeshIndex], coordSommets, coordTexture);
            }
            // end of facet processing

            // submeshes creation

            // load texture
            byte[] _imgBytes = File.ReadAllBytes(_texPath);
            _texture = new Texture2D(2, 2);
            _texture.LoadImage(_imgBytes);

            // GameObjects creation an rendering
            finalTerrain = new GameObject();
            finalTerrain.transform.SetParent(gameObject.transform);
            finalTerrain.name = new FileInfo(_path).Name.Trim().Split('.')[0];

            Terrains = new List <GameObject>();
            _meshes  = new List <Mesh>();
            RenderMeshes(meshnumber, finalTerrain.transform, ref Terrains, ref _meshes, ref _vertexArrayList, ref _uvArrayList, ref _triangleArrayList, _texture);
            // reset hint message to void when the terrain is fully loaded
            EventManager.TriggerEvent("LobbyHintMessage", new EventParam("Vous pouvez sélectionner un point de départ sur le terrain à votre droite."));
            // trigger event to enable terrain buttons when loading is over
        }
    }