コード例 #1
0
    public void SpawnVoxels(VoxelizationInfo info)
    {
        List <VoxelizationServer.AABCGrid> aABCGrids = info.aABCGrids;

        //int total = 0;
        if (aABCGrids != null)
        {
            foreach (VoxelizationServer.AABCGrid aABCGrid in aABCGrids)
            {
                Vector3 preCalc = aABCGrid.GetOrigin();
                for (short x = 0; x < aABCGrid.GetWidth(); ++x)
                {
                    for (short y = 0; y < aABCGrid.GetHeight(); ++y)
                    {
                        for (short z = 0; z < aABCGrid.GetDepth(); ++z)
                        {
                            if (aABCGrid.IsAABCActiveUnsafe(x, y, z))
                            {
                                Vector3 cubeCenter = aABCGrid.GetAABCCenterUnsafe(x, y, z) + preCalc;

                                voxelController = voxelPool.GetObject();
                                if (voxelController != null)
                                {
                                    //++total;
                                    Transform voxelTrans = voxelController.gameObject.transform;
                                    voxelTrans.position = cubeCenter;
                                    voxelTrans.rotation = Quaternion.identity;
                                    //voxelTrans.rotation = Random.rotation;
                                    voxelTrans.localScale = info.voxelScale;
                                    if (!info.randomMaterial)
                                    {
                                        voxelController.GetComponent <Renderer>().sharedMaterial = info.mat;
                                    }
                                    else
                                    {
                                        voxelController.GetComponent <Renderer>().sharedMaterial = colorObjMng.GetVoxelRandomMaterial();
                                    }

                                    voxelController.spawnLevels = 1;
                                }
                            }
                        }
                    }
                }

                //Set a collider in place to make voxels "explode"
                if (info.spawnCollider)
                {
                    GameObject voxelCollider = voxelColliderPool.GetObject();
                    if (voxelCollider != null)
                    {
                        voxelCollider.transform.localScale = info.voxelColliderScale;
                        voxelCollider.transform.position   = aABCGrid.GetCenter();
                    }
                }
            }
        }
        //Debug.Log("Spider spawned: " + total);
    }
コード例 #2
0
    public VoxelController GetVoxel(ChromaColor color)
    {
        //Get a voxel from pool
        VoxelController voxel = voxelPool.GetObject();

        if (voxel != null)
        {
            voxel.GetComponent <Renderer>().sharedMaterial = GetMaterial(voxelMats, color);
        }

        return(voxel);
    }
コード例 #3
0
    //Voxel methods
    public VoxelController GetVoxel()
    {
        //Get a voxel from pool
        VoxelController voxel = voxelPool.GetObject();

        if (voxel != null)
        {
            voxel.GetComponent <Renderer>().sharedMaterial = currentVoxelMat;
        }

        return(voxel);
    }
コード例 #4
0
    public void SpawnVoxels()
    {
        //int total = 0;
        if (aABCGrids != null)
        {
            foreach (VoxelizationServer.AABCGrid aABCGrid in aABCGrids)
            {
                Vector3 preCalc = aABCGrid.GetOrigin();
                for (short x = 0; x < aABCGrid.GetWidth(); ++x)
                {
                    for (short y = 0; y < aABCGrid.GetHeight(); ++y)
                    {
                        for (short z = 0; z < aABCGrid.GetDepth(); ++z)
                        {
                            if (aABCGrid.IsAABCActiveUnsafe(x, y, z))
                            {
                                Vector3 cubeCenter = aABCGrid.GetAABCCenterUnsafe(x, y, z) + preCalc;
                                /*voxel = voxelPool.GetObject();
                                if (voxel != null)
                                {
                                    voxel.transform.position = cubeCenter;
                                    voxel.transform.rotation = Quaternion.identity;
                                    voxel.GetComponent<Renderer>().material = mat;
                                    voxel.SetActive(true);
                                }*/
                                //++total;
                                voxelController = voxelPool.GetObject();
                                if(voxelController != null)
                                {
                                    Transform voxelTrans = voxelController.gameObject.transform;
                                    voxelTrans.position = cubeCenter;
                                    //voxelTrans.rotation = Quaternion.identity;
                                    voxelTrans.rotation = Random.rotation;
                                    voxelTrans.localScale = voxelScale;
                                    if(!randomMaterial)
                                    {
                                        voxelController.GetComponent<Renderer>().material = mat;
                                    }
                                    else
                                    {
                                        voxelController.GetComponent<Renderer>().material = colorObjMng.GetVoxelRandomMaterial();
                                    }
                                                                        
                                    //voxelController.gameObject.SetActive(true);
                                    voxelController.spawnLevels = 1;
                                }

                                //Set a collider in place to make voxels "explode"
                                GameObject voxelCollider = voxelColliderPool.GetObject();
                                if (voxelCollider != null)
                                {
                                    voxelCollider.transform.position = cubeCenter;
                                }
                            }
                        }
                    }
                }
            }
        }
        //Debug.Log("Spider spawned: " + total);
    }