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); } } }
private void LoadPointCloud(string pcFolder) { string[] pcFilePath = Directory.GetFiles(pcFolder); pcList = new List <PointcloudData>(); foreach (string path in pcFilePath) { //check extension is .ply file if (Path.GetExtension(path) == ".ply") { string pcname = Path.GetFileNameWithoutExtension(path); PlyLoader plyloader = new PlyLoader(); Mesh pcMesh = null; List <Vector3> vertices = null; List <Color32> colors = null; List <Vector3> normals = null; (pcMesh, vertices, colors, normals) = plyloader.ImportFile(path); Material mat = new Material(vertexColorShader); GameObject pcObj = new GameObject(plyloader.fileName, typeof(MeshFilter), typeof(MeshRenderer)); pcObj.name = pcname; pcObj.GetComponent <MeshFilter>().mesh = pcMesh; pcObj.GetComponent <MeshRenderer>().material = mat; pcObj.AddComponent <ExposeToEditor>(); pcObj.SetActive(true); GameObject cone = GameObject.Instantiate(conePrefabs); cone.AddComponent <BoxCollider>(); cone.SetActive(true); cone.transform.parent = pcObj.transform; pcObj.transform.parent = pointcloud.transform; string camfilepath = pcFolder + "\\cam\\" + pcname + ".cam"; float f, cx, cy; f = cx = cy = 0; bool has_cam = false; if (File.Exists(camfilepath)) { has_cam = true; string[] lines = System.IO.File.ReadAllLines(camfilepath); string[] tokens = lines[1].Split(' '); f = float.Parse(tokens[0]); cx = float.Parse(tokens[4]); cy = float.Parse(tokens[5]); } DateTime dt = DateTime.Now; string ts = dt.ToString("yyyyMMdd"); string[] tmp = pcname.Split('_'); string camid = tmp[tmp.Length - 1]; PointcloudData data = new PointcloudData(vertices, colors, normals, pcObj, pcname, has_cam, f, cx, cy, ts, camid); pcList.Add(data); selectPanel.createToggle(pcname); } } }
// Use this for initialization void Start() { PlyLoader loader = new PlyLoader(); //Mesh mesh = loader.load("2PTC_EI_bs_1.ply"); Mesh mesh = loader.load("cube.ply"); GameObject g = new GameObject(); MeshFilter mf = g.AddComponent <MeshFilter>(); mf.mesh = mesh; MeshRenderer mr = g.AddComponent <MeshRenderer>(); }
// Use this for initialization void Start() { PlyLoader loader = new PlyLoader(); //Mesh [] mesh = loader.load("2PTC_EI_bs_1.ply"); Mesh [] mesh = loader.load("cube.ply"); for (int i = 0; i != mesh.Length; ++i) { GameObject g = new GameObject(); mesh[i].name = g.name = "mesh" + i; MeshFilter mf = g.AddComponent <MeshFilter>(); mf.mesh = mesh[i]; MeshRenderer mr = g.AddComponent <MeshRenderer>(); } }