示例#1
0
        private void CreateMesh(EndeffectorData endEffector, MeshFilter tool)           //, double[] tcp
        {
            List <Vector3> vertices  = new List <Vector3>();
            List <int>     triangles = new List <int>();

            if (endEffector.vertices != null)
            {
                                #if DEBUG
                Debug.Log("Robot: Adding Verticies . . . !");
                                #endif
                for (int j = 0; j < endEffector.vertices.Count; j++)
                {
                    vertices.Add(new Vector3(endEffector.vertices[j][0],
                                             endEffector.vertices[j][1],
                                             endEffector.vertices[j][2]));
                }
            }

            if (endEffector.faces != null)
            {
                                #if DEBUG
                Debug.Log("Robot: Adding Faces . . . !");
                                #endif
                for (int j = 0; j < endEffector.faces.Count; j++)
                {
                    triangles.Add(endEffector.faces[j][1]);
                    triangles.Add(endEffector.faces[j][2]);
                    triangles.Add(endEffector.faces[j][3]);

                    if ((endEffector.faces[j][0] == 1))
                    {
                        triangles.Add(endEffector.faces[j][1]);
                        triangles.Add(endEffector.faces[j][3]);
                        triangles.Add(endEffector.faces[j][4]);
                    }
                }
            }
            tool.mesh = MeshUtilities.DecodeMesh(vertices, triangles);
            tool.transform.Rotate(0, 180, -90);
        }
示例#2
0
        // Decode Received Data.
        public void ProcessMesh(List <MeshData> receivedMeshes, SourceType sourceType)
        {
                        #if DEBUG
            Debug.Log("Mesh: Received Count: " + receivedMeshes.Count + ". Type: " + (int)sourceType);
                        #endif

            // Check for C-plane
            if (!ObjectManager.instance.CheckCPlane())
            {
                return;
            }

            // Find relevant objects based on source to update
            GameObject[] goRelevantMeshes;
            string       currentTag;
            GameObject   currentPrefab;
            switch (sourceType)
            {
            case (SourceType.TCP):
                                 #if DEBUG
                Debug.Log("Mesh: TCP");
                                 #endif
                currentPrefab = this.goPrefabMesh;
                currentTag    = this.tagMesh;
                break;

            case (SourceType.UDP):
                                 #if DEBUG
                Debug.Log("Mesh: UDP");
                                 #endif
                currentPrefab = this.goPrefabMeshPlus;
                currentTag    = this.tagMeshPlus;
                break;

            default:
                return;
            }
            goRelevantMeshes = GameObject.FindGameObjectsWithTag(currentTag);

            List <Vector3> currentVertices = new List <Vector3>();
            List <int>     currentFaces    = new List <int>();
            List <Color>   currentColors   = new List <Color>();
            // Loop through all received meshes.
            for (int i = 0; i < receivedMeshes.Count; i++)
            {
                // Condition Vertex based data (points and colors). // Later: normals etc.
                for (int j = 0; j < receivedMeshes[i].vertices.Count; j++)
                {
                    currentVertices.Add(new Vector3(receivedMeshes[i].vertices[j][0],
                                                    receivedMeshes[i].vertices[j][1],
                                                    receivedMeshes[i].vertices[j][2]));
                    int colorIndex = (receivedMeshes[i].colors.Count == receivedMeshes[i].vertices.Count) ? j : 0;
                    currentColors.Add(new Color((float)receivedMeshes[i].colors[colorIndex][1] / 255.0f,
                                                (float)receivedMeshes[i].colors[colorIndex][2] / 255.0f,
                                                (float)receivedMeshes[i].colors[colorIndex][3] / 255.0f,
                                                1.0f));
                }
                float alpha = (float)receivedMeshes[i].colors[0][0] / 255.0f;
                // Condition Faces.
                for (int j = 0; j < receivedMeshes[i].faces.Count; j++)
                {
                    currentFaces.Add(receivedMeshes[i].faces[j][1]);
                    currentFaces.Add(receivedMeshes[i].faces[j][2]);
                    currentFaces.Add(receivedMeshes[i].faces[j][3]);
                    // If quad - add second face.
                    if ((receivedMeshes[i].faces[j][0] == 1))
                    {
                        currentFaces.Add(receivedMeshes[i].faces[j][1]);
                        currentFaces.Add(receivedMeshes[i].faces[j][3]);
                        currentFaces.Add(receivedMeshes[i].faces[j][4]);
                    }
                }

                // Set Values
                GameObject meshInstance;
                if (i < goRelevantMeshes.Length)
                {
                                        #if DEBUG
                    Debug.Log("Mesh: Updating old Mesh");
                                        #endif
                    meshInstance = goRelevantMeshes[i];
                }
                else
                {
                                        #if DEBUG
                    Debug.Log("Mesh: Adding new Mesh");
                                        #endif
                    meshInstance = Instantiate(currentPrefab, ObjectManager.instance.cPlane.transform.position, ObjectManager.instance.cPlane.transform.rotation, ObjectManager.instance.cPlane.transform);
                }
                meshInstance.GetComponent <Renderer>().material.SetFloat("_ShadowStrength", 1.0f);
                meshInstance.GetComponent <Renderer>().material.SetFloat("_Alpha", alpha);
                meshInstance.GetComponent <MeshFilter>().mesh = MeshUtilities.DecodeMesh(currentVertices, currentFaces, currentColors);
            }

            // Delete Extraneous Meshes.
            if (goRelevantMeshes.Length > receivedMeshes.Count)
            {
                                #if DEBUG
                Debug.Log("Mesh: Meshes extra deleting.");
                                #endif
                DeleteMeshes(sourceType, receivedMeshes.Count);
            }
        }