Ejemplo n.º 1
0
 // Use this for initialization
 void Start()
 {
     pointArr   = new Vector3[1000];
     pointStack = new IndexStack <Vector3> (pointArr);
     centroid   = new Vector3(0, 0, 1);
     controlObj.GetComponent <ParticleSystem>().Stop();
 }
Ejemplo n.º 2
0
    // Use this for initialization
    void Start()
    {
        pointArr      = new int[frontPointCount];
        frontRenderer = new IndexStack <int> (pointArr);

        handPointArr = new int[frontPointCount];
        handPoints   = new IndexStack <int> (handPointArr);
    }
Ejemplo n.º 3
0
    public static void Listen(IndexStack <LuaValue> Stack)
    {
        LuaFunction func = (LuaFunction)Stack.Pop();
        LuaValue    val  = Stack.Pop();

        HttpBinding binding = new HttpBinding();

        binding.Path = val.String();

        binding.Function = func;

        Bindings.Add(binding);
    }
Ejemplo n.º 4
0
    // Use this for initialization
    void Start()
    {
        vxe             = VoxelExtractionPointCloud.Instance;
        biome           = BiomeScript.Instance;
        mybiome         = biome.biomeArea [0].biome;
        occupiedNearMe  = new List <Chunks> ();
        assetChunkTable = new Dictionary <Vec3Int, GameObject> ();

        if (playerTrans == null)
        {
            playerTrans = GameObject.FindWithTag("Player").GetComponent <Transform> ();
        }

        spawns = new IndexStack <SpawnObject> (new SpawnObject[max_spawns + 20]);
        StartCoroutine(FullPullSpawn());
        StartCoroutine(MaintainSpawns());
    }
Ejemplo n.º 5
0
    // Use this for initialization
    void Awake()
    {
        vxe       = VoxelExtractionPointCloud.Instance;
        chunkObjs = vxe.chunkGameObjects;

        num_chunks_x = vxe.num_chunks_x;
        num_chunks_y = vxe.num_chunks_y;
        num_chunks_z = vxe.num_chunks_z;

        biomeOccupiedChunks = new IndexStack <Vec3Int> [activeBiomes];
        for (int i = 0; i < activeBiomes; i++)
        {
            biomeOccupiedChunks[i] = new IndexStack <Vec3Int>(new Vec3Int[1000]);
        }

        initBiomes();
    }
Ejemplo n.º 6
0
    void Start()
    {
        //spawneditems = new GameObject[items.Length];


        //for (int i=0; i<items.Length; i++)
        //	spawneditems [i] = null;

        prevpositions = new IndexStack <Vec3Int> (new Vec3Int[20]);

        vxe = VoxelExtractionPointCloud.Instance;
        if (camera == null)
        {
            camera = vxe.camera;
        }
        biome = BiomeScript.Instance;
    }
Ejemplo n.º 7
0
    public static void Print(IndexStack <LuaValue> Stack)
    {
        LuaValue val = Stack.Pop();

        Console.WriteLine(val.String());
    }
Ejemplo n.º 8
0
    // Use this for initialization
    void Start()
    {
        vxe = VoxelExtractionPointCloud.Instance;
        biome = BiomeScript.Instance;
        mybiome = biome.biomeArea [0].biome;
        occupiedNearMe = new List<Chunks> ();
        assetChunkTable = new Dictionary<Vec3Int, GameObject> ();

        if (playerTrans == null)
            playerTrans = GameObject.FindWithTag ("Player").GetComponent<Transform> ();

        InitializeEnvironmentBiome (ref desertGameObjects, "DesertAssets", ref desertAssets);
        InitializeEnvironmentBiome (ref grassGameObjects, "GrassAssets", ref grassAssets);
        InitializeEnvironmentBiome (ref IceGameObjects, "IceAssets", ref iceAssets);
        InitializeEnvironmentBiome (ref marshGameObjects, "MarshAssets", ref marshAssets);
        spawns = new IndexStack<SpawnObject> (new SpawnObject[max_spawns]);
        StartCoroutine (FullPullSpawn ());
        StartCoroutine (MaintainSpawns ());
    }
Ejemplo n.º 9
0
    /// <summary>
    /// Use this for initialization.
    /// </summary>
    public void Start()
    {
        if(m_updatePointsMesh)
        {
            pointArr = new Vector3[frontPointCount];
            frontRenderer = new IndexStack<Vector3> (pointArr);
        }
        m_tangoApplication = FindObjectOfType<TangoApplication>();
        m_tangoApplication.Register(this);

        m_unityWorldTStartService.SetColumn(0, new Vector4(1.0f, 0.0f, 0.0f, 0.0f));
        m_unityWorldTStartService.SetColumn(1, new Vector4(0.0f, 0.0f, 1.0f, 0.0f));
        m_unityWorldTStartService.SetColumn(2, new Vector4(0.0f, 1.0f, 0.0f, 0.0f));
        m_unityWorldTStartService.SetColumn(3, new Vector4(0.0f, 0.0f, 0.0f, 1.0f));

        // Assign triangles, note: this is just for visualizing point in the mesh data.
        m_points = new Vector3[MAX_POINT_COUNT];

        m_mesh = GetComponent<MeshFilter>().mesh;
        m_mesh.Clear();

        m_renderer = GetComponent<Renderer>();
        m_rand = new System.Random();
    }
Ejemplo n.º 10
0
    void buildChunkMesh(Chunks chunk, Vec3Int chunkCoords, Mesh _mesh)
    {
        int[]            indices = new int[ChunkTemplate.Instance.vertex_count * 3];
        IndexStack <int> istack  = new IndexStack <int>(indices);


        for (int x = 0; x < vxe.chunk_size; x++)
        {
            for (int y = 0; y < vxe.chunk_size; y++)
            {
                for (int z = 0; z < vxe.chunk_size; z++)
                {
                    Vec3Int vcoord = new Vec3Int(x, y, z);
                    Voxel   voxel  = chunk.getVoxel(vcoord);

                    if (voxel.isOccupied())
                    {
                        Vector3 vwrldcoord = vxe.FromGrid(chunkCoords * vxe.chunk_size + vcoord);
                        if ((vwrldcoord - camera.transform.position).sqrMagnitude > 0.64f)
                        {
                            continue;
                        }

                        //front
                        if (voxel.getFace(VF.VX_FRONT_SHOWN))
                        {
                            //front
                            istack.push(chunk.getIndex(x, y, z + 1, DIR.DIR_FRONT));
                            istack.push(chunk.getIndex(x + 1, y, z + 1, DIR.DIR_FRONT));
                            istack.push(chunk.getIndex(x + 1, y + 1, z + 1, DIR.DIR_FRONT));
                            istack.push(chunk.getIndex(x, y + 1, z + 1, DIR.DIR_FRONT));
                        }

                        if (voxel.getFace(VF.VX_RIGHT_SHOWN))
                        {
                            //right
                            istack.push(chunk.getIndex(x + 1, y, z, DIR.DIR_RIGHT));
                            istack.push(chunk.getIndex(x + 1, y + 1, z, DIR.DIR_RIGHT));
                            istack.push(chunk.getIndex(x + 1, y + 1, z + 1, DIR.DIR_RIGHT));
                            istack.push(chunk.getIndex(x + 1, y, z + 1, DIR.DIR_RIGHT));
                        }

                        if (voxel.getFace(VF.VX_BACK_SHOWN))
                        {
                            //back
                            istack.push(chunk.getIndex(x, y, z, DIR.DIR_BACK));
                            istack.push(chunk.getIndex(x, y + 1, z, DIR.DIR_BACK));
                            istack.push(chunk.getIndex(x + 1, y + 1, z, DIR.DIR_BACK));
                            istack.push(chunk.getIndex(x + 1, y, z, DIR.DIR_BACK));
                        }

                        if (voxel.getFace(VF.VX_LEFT_SHOWN))
                        {
                            //left
                            istack.push(chunk.getIndex(x, y, z, DIR.DIR_LEFT));
                            istack.push(chunk.getIndex(x, y, z + 1, DIR.DIR_LEFT));
                            istack.push(chunk.getIndex(x, y + 1, z + 1, DIR.DIR_LEFT));
                            istack.push(chunk.getIndex(x, y + 1, z, DIR.DIR_LEFT));
                        }

                        if (voxel.getFace(VF.VX_TOP_SHOWN))
                        {
                            //top
                            istack.push(chunk.getIndex(x, y + 1, z, DIR.DIR_UP));
                            istack.push(chunk.getIndex(x, y + 1, z + 1, DIR.DIR_UP));
                            istack.push(chunk.getIndex(x + 1, y + 1, z + 1, DIR.DIR_UP));
                            istack.push(chunk.getIndex(x + 1, y + 1, z, DIR.DIR_UP));
                        }

                        if (voxel.getFace(VF.VX_BOTTOM_SHOWN))
                        {
                            //bottom
                            istack.push(chunk.getIndex(x, y, z, DIR.DIR_DOWN));
                            istack.push(chunk.getIndex(x + 1, y, z, DIR.DIR_DOWN));
                            istack.push(chunk.getIndex(x + 1, y, z + 1, DIR.DIR_DOWN));
                            istack.push(chunk.getIndex(x, y, z + 1, DIR.DIR_DOWN));
                        }
                    }
                }
            }
        }

        int[] indexArray = new int[istack.getCount()];
        System.Array.Copy(istack.getArray(), indexArray, istack.getCount());

        _mesh.SetIndices(indexArray, MeshTopology.Quads, 0);
    }
Ejemplo n.º 11
0
    IEnumerator SpawnItems()
    {
        yield return(new WaitForSeconds(5.0f));

        Vector3 coords = Vector3.zero, norm = Vector3.zero;

        bool hitsomething = false;

        while (!hitsomething)
        {
            hitsomething = vxe.RayCast(camera.transform.position, Vector3.down, 64, ref coords, ref norm, 1.0f);
            yield return(null);
        }

        Random.seed = System.DateTime.Now.Millisecond;
        floorChunkY = vxe.getChunkCoords(coords).y;
        Vec3Int prevcc  = new Vec3Int(vxe.num_chunks_x / 2, vxe.num_voxels_y / 2, vxe.num_chunks_z / 2);
        Vector2 prevdir = Vector2.zero;

        for (int s = 0; s < stages.Length; s++)
        {
            currentStage = s;
            ItemInfo[] items = stages[s].items;
            nextStage = false;

            for (int i = 0; i < items.Length; i++)
            {
                int biomeIndex = (int)items[i].biome;
                IndexStack <Vec3Int> occupiedChunks =
                    items[i].biome == BIOMES.none ? vxe.occupiedChunks : BiomeScript.Instance.biomeOccupiedChunks[biomeIndex];

                bool spawned  = false;
                int  maxdist  = 3;
                int  attempts = 0;
                while (!spawned)
                {
                    int chunkx;
                    int chunkz;

                    while (true)
                    {
                        int count  = occupiedChunks.getCount();
                        int period = Random.Range(0, count);

                        Vec3Int randomCC = occupiedChunks.peek(period);
                        chunkx = randomCC.x;
                        chunkz = randomCC.z;


                        bool isFarEnough = true;
                        int  start       = Mathf.Max(0, prevpositions.getCount() - 3);

                        for (int k = start; k < prevpositions.getCount(); k++)
                        {
                            Vec3Int pcc  = prevpositions.peek(k);
                            int     dist = (chunkx - pcc.x) * (chunkx - pcc.x) + (chunkz - pcc.z) * (chunkz - pcc.z);
                            Debug.Log(dist);
                            if (dist < maxdist * maxdist)
                            {
                                isFarEnough = false;
                                break;
                            }
                        }


                        if (SpawnCount == 0 || isFarEnough)
                        {
                            break;
                        }

                        attempts++;

                        if (attempts % 20 == 0)
                        {
                            if (maxdist > 1)
                            {
                                maxdist--;
                            }
                        }

                        yield return(null);
                    }



                    Chunks chunk = null;

                    for (int k = floorChunkY + range; k >= floorChunkY; k--)
                    {
                        chunk = vxe.grid.voxelGrid [chunkx, k, chunkz];
                        Chunks chunkup   = vxe.grid.voxelGrid [chunkx, k + 1, chunkz];
                        bool   isthereUp = (chunkup != null && chunkup.voxel_count > 3);

                        if (!isthereUp && chunk != null && chunk.voxel_count > 60 && vxe.isChunkASurface(DIR.DIR_UP, chunk, 0.5f))
                        {
                            Vector3 chunkBaseCoords = new Vector3(chunkx, k, chunkz) * vxe.chunk_size;



                            for (int ox = 0; ox < vxe.chunk_size; ox++)
                            {
                                int x = (ox + vxe.chunk_size / 2 - 1) % vxe.chunk_size;
                                for (int oz = 0; oz < vxe.chunk_size; oz++)
                                {
                                    int z = (oz + vxe.chunk_size / 2 - 1) % vxe.chunk_size;
                                    for (int y = vxe.chunk_size - 1; y >= 0; y--)
                                    {
                                        Voxel vx = chunk.getVoxel(new Vec3Int(x, y, z));

                                        if (vx.isOccupied() && vxe.voxelHasSurface(vx, VF.VX_TOP_SHOWN))
                                        {
                                            Vector3 voxelCoords = vxe.FromGridUnTrunc(chunkBaseCoords + new Vector3(x, y, z));
                                            if (voxelCoords.y < coords.y + items [i].minSpawnHeightOffFloor * vxe.voxel_size ||
                                                voxelCoords.y > coords.y + items [i].maxSpawnHeightOffFloor * vxe.voxel_size)
                                            {
                                                continue;
                                            }

                                            GameObject newItem = (GameObject)Instantiate(items [i].item, voxelCoords + new Vector3(0, vxe.voxel_size, 0), Quaternion.identity);
                                            newItem.SetActive(true);


                                            newItem.GetComponent <VoxelParent>().chunkCoords = new Vec3Int(chunkx, k, chunkz);

                                            prevpositions.push(new Vec3Int(chunkx, 0, chunkz));

                                            SpawnCount++;

                                            spawned = true;
                                            Debug.Log("spawned!");
                                            canSpawn = false;
                                            goto imout;
                                        }
                                        yield return(null);
                                    }
                                }
                            }
                        }
                    }

imout:

                    if (spawned && !stages[s].allAtOnce)
                    {
                        while (!canSpawn)
                        {
                            yield return(new WaitForSeconds(1.0f));
                        }
                    }
                    else
                    {
                        yield return(null);
                    }
                }
            }

            while (stages[s].stageWait && !nextStage)
            {
                yield return(new WaitForSeconds(1.0f));
            }
        }
    }