예제 #1
0
 public void CreateAllGameObjects(PointMeshConfiguration configuration)
 {
     CreateGameObjects(configuration);
     for (int i = 0; i < 8; i++)
     {
         if (children[i] != null)
         {
             children[i].CreateAllGameObjects(configuration);
         }
     }
 }
예제 #2
0
    // === FUNCTIONS ===
    // Load PointCloud until level 5 and add to parentObject
    public IEnumerator LoadPointCloud(string cloudPath, GameObject parentObject, int level = 4, int pointRadius = 5)
    {
        meshConfiguration = new PointMeshConfiguration(parentObject, level, pointRadius);
        listNodes         = new List <PotreeNode>();

        // point cloud metadata
        pointCloudMetaData = new PointCloudMetaData();
        string jsonfile;

        using (StreamReader reader = new StreamReader(new FileStream(cloudPath + "/cloud.js", FileMode.Open, FileAccess.Read, FileShare.Read)))
        {
            jsonfile = reader.ReadToEnd();
            reader.Dispose();
        }
        PointCloudMetaData metaData = PointCloudMetaData.ReadFromJson(jsonfile, meshConfiguration.moveToOrigin);

        metaData.cloudPath = cloudPath;
        metaData.cloudName = cloudPath.Substring(0, cloudPath.Length - 1).Substring(cloudPath.Substring(0, cloudPath.Length - 1).LastIndexOf("/") + 1);

        // root node
        string     dataRPath = metaData.cloudPath + metaData.octreeDir + "/r/";
        PotreeNode rootNode  = new PotreeNode("", metaData, metaData.boundingBox, null);

        // load hierarchy
        LoadHierarchy(dataRPath, metaData, rootNode);

        // load pointcloud data
        //LoadAllPoints(dataRPath, metaData, rootNode);
        GetListNodes(dataRPath, metaData, rootNode);

        // now load data for nodes
        float startTime = DateTime.Now.Millisecond;

        foreach (PotreeNode node in listNodes)
        {
            LoadPoints(dataRPath, metaData, node);
            //Debug.Log(DateTime.Now.Millisecond);
            if (DateTime.Now.Millisecond - startTime > 100.0f)
            {
                //Debug.Log("resume display");
                startTime = DateTime.Now.Millisecond;
                yield return(null);
            }
        }
        listNodes.Clear();

        // create gameobjects
        rootNode.CreateAllGameObjects(meshConfiguration);

        yield return(null);
    }
예제 #3
0
    public void CreateGameObjects(PointMeshConfiguration configuration)
    {
        int max = configuration.GetMaximumPointsPerMesh();

        if (verticesToStore == null || colorsToStore == null)
        {
            return;
        }
        if (verticesToStore.Length <= max)
        {
            GameObject gO = configuration.CreateGameObject(metaData.cloudName + "/" + "r" + name + " (" + verticesToStore.Length + ")", verticesToStore, colorsToStore, boundingBox);
            if (GetLevel() == 0)
            {
                BoxCollider bC = gO.AddComponent <BoxCollider>();
                bC.enabled = false;
            }

            gameObjects.Add(gO);
        }
        else
        {
            int       amount       = Math.Min(max, verticesToStore.Length);
            int       index        = 0; //name index
            Vector3[] restVertices = verticesToStore;
            Color[]   restColors   = colorsToStore;
            while (amount > 0)
            {
                Vector3[] vertices = restVertices.Take(amount).ToArray();
                Color[]   colors   = restColors.Take(amount).ToArray();;
                restVertices = restVertices.Skip(amount).ToArray();
                restColors   = restColors.Skip(amount).ToArray();
                GameObject gO = configuration.CreateGameObject(metaData.cloudName + "/" + "r" + name + "_" + index + " (" + vertices.Length + ")", vertices, colors, boundingBox);
                if (GetLevel() == 0)
                {
                    BoxCollider bC = gO.AddComponent <BoxCollider>();
                    bC.enabled = false;
                }
                gameObjects.Add(gO);
                amount = Math.Min(max, vertices.Length);
                index++;
            }
        }
    }