Exemplo n.º 1
0
        public void Load()
        {
            string[] splits = node.modelId.Split('.');
            if (splits[0] == "scannetv2")
            {
                string pathToModel = Config.SCANNET_HOME + "scans/" + splits[1] + "/" + splits[1] + "_vh_clean_2.ply";

                GameObject loadedObject = new GameObject();
                loadedObject.name = splits[1];
                PlyLoader  loader = new PlyLoader();
                Mesh       mesh   = loader.load(pathToModel);
                MeshFilter mf     = loadedObject.AddComponent <MeshFilter>();
                mf.mesh = mesh;
                MeshRenderer mr = loadedObject.AddComponent <MeshRenderer>();
                mr.material = new Material(Shader.Find("Custom/VertexColor"));

                // Add a MeshCollder to every part of the model
                loadedObject.AddComponent <MeshCollider>();
                // Add rigid body to the gameobject and fix the rotation
                Rigidbody rigid = loadedObject.AddComponent <Rigidbody>();
                rigid.isKinematic = true;
                rigid.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ | RigidbodyConstraints.FreezePositionY;

                loadedObject.transform.parent = transform;
                // Apply the transform of the node
                if (node.transform != null)
                {
                    Matrix4x4 matrix = TransformUtils.Array2Matrix4x4(node.transform);
                    TransformUtils.SetTransformFromMatrix(loadedObject.transform, ref matrix);
                }
            }
        }