Ejemplo n.º 1
0
    // Note: now this function is invoked to attack building
    public void AlterVoxelInChunk(int vx, int vy, int vz, VFVoxel voxel, bool writeType, bool writeVolume)
    {
        if (!AttackVoxel(vx, vy, vz, voxel.Volume))
        {
            return;
        }

        //Instantiate effect
        int    index = UnityEngine.Random.Range(1, 3);
        string path  = "Prefab/Particle/FX_voxel_block_collapsing_0" + index;

        GameObject particleResources = Resources.Load(path) as GameObject;

        if (particleResources != null)
        {
            GameObject particle = GameObject.Instantiate(particleResources, new Vector3(vx, vy, vz), Quaternion.identity) as GameObject;
            GameObject.Destroy(particle, 2.5f);
        }

        int n = Voxels.DirtyChunkList.Count;

        for (int i = 0; i < n; i++)
        {
            SaveLoad.AddChunkToSaveList(Voxels.DirtyChunkList[i]);
        }
    }
Ejemplo n.º 2
0
    public void UpdateDecal()
    {
        if (_lifetime > 0)
        {
            _lifetime--;
            VFVoxel groundVoxel = VFVoxelTerrain.self.Voxels.SafeRead((int)transform.position.x, (int)transform.position.y, (int)transform.position.z);
            if (groundVoxel.Volume <= 0x40)
            {
                _lifetime = 0;
            }

            if (_lifetime <= 0)
            {
                _r.material.color = new Color(1, 1, 1, 0);
                _r.enabled        = false;
            }
            else if (_lifetime > FadeOutCnt)
            {
                _r.material.color = new Color(1, 1, 1, 1);
            }
            else
            {
                _r.material.color = new Color(1, 1, 1, ((float)_lifetime) / FadeOutCnt);
            }
        }
    }
Ejemplo n.º 3
0
    public bool WriteVoxelAtIdx4LodUpdate(int x, int y, int z, VFVoxel voxel)
    {
        if (_chunkData == null || _chunkData == S_ChunkDataNull)
        {
            return(false);
        }
        try{
            if (IsHollow && !_helperProc.ChunkProcExtractData(this))
            {
                return(false);
            }

            int index   = OneIndexNoPrefix(x, y, z);
            int indexVT = index * VFVoxel.c_VTSize;
            _chunkData[indexVT]     = voxel.Volume;
            _chunkData[indexVT + 1] = voxel.Type;
            UpdateTimeStamp();
            if (_node == null)
            {
                AddToBuildList();
            }
            else if (_node.IsInReq)
            {
                AddToBuildList();
            }
        }
        catch
        {
            Debug.LogWarning("[VFTERRAIN]:Failed to write lod voxel[" + x + "," + y + "," + z + "] of ChunkData" + ChunkPosLod);
        }
        return(true);
    }
Ejemplo n.º 4
0
    public bool WriteVoxelAtIdxNoReq(int x, int y, int z, VFVoxel voxel, bool bLodUpdate = false)
    {
        if (_chunkData == S_ChunkDataNull)
        {
            return(false);
        }
        try{
            if (IsHollow && !_helperProc.ChunkProcExtractData(this))
            {
                return(false);
            }

            int index   = OneIndex(x, y, z);
            int indexVT = index * VFVoxel.c_VTSize;
            _chunkData[indexVT]     = voxel.Volume;
            _chunkData[indexVT + 1] = voxel.Type;
            UpdateTimeStamp();
        }
        catch
        {
            Debug.LogWarning("[VFTERRAIN]:Failed to write voxel[" + x + "," + y + "," + z + "] of ChunkData" + ChunkPosLod);
        }

        if (bLodUpdate && VFVoxelTerrain.self.LodDataUpdate != null)
        {
            VFVoxelTerrain.self.LodDataUpdate.InsertUpdateCoord(x, y, z, _chunkPosLod);
        }
//		VFVoxelTerrain.self.lodDataUpdate.threadProc();

        return(true);
    }
Ejemplo n.º 5
0
    VFVoxel GetAverageVoxel2(VFVoxelChunkData inputChunk, IntVector3 InChunkPos)
    {
        int  volumeSum = 0;
        byte voxelType = 0;

        //int typeCount = 0;
        VFVoxel[] eight = new VFVoxel[8];
        // sample 8 points
        for (int j = 0; j < 8; j++)
        {
            int xInc = (j & 1) > 0 ? 1 : 0;
            int yInc = (j & 2) > 0 ? 1 : 0;
            int zInc = (j & 4) > 0 ? 1 : 0;
            try
            {
                eight[j] = inputChunk.ReadVoxelAtIdx(InChunkPos.x + xInc, InChunkPos.y + yInc, InChunkPos.z + zInc);
            }
            catch {
                //int asdglfg = 0;
            }
//					int idx = VFVoxelChunkData.OneIndex(x + xInc,y + yInc,z + zInc) * VFVoxel.c_VTSize;
            volumeSum += eight[j].Volume;

            if (eight[j].Type > 0)
            {
                voxelType = eight[j].Type;
            }
        }
        VFVoxel ret = new VFVoxel((byte)(volumeSum >> 3), voxelType);

        return(ret);
    }
Ejemplo n.º 6
0
    public void AlterVoxelSphere(int x, int y, int z, int radius, float coreVolume, byte voxelType, bool writeType)
    {
        int x1 = x - radius;
        int y1 = y - radius;
        int z1 = z - radius;
        int x2 = x + radius;
        int y2 = y + radius;
        int z2 = z + radius;

        float radiusf = (float)radius;

        for (int px = x1; px < x2; ++px)
        {
            for (int py = y1; py < y2; ++py)
            {
                for (int pz = z1; pz < z2; ++pz)
                {
                    Vector3 v    = new Vector3(px - x, py - y, pz - z);
                    float   bpos = radiusf - v.magnitude;
                    if (bpos > 0)
                    {
                        VFVoxel voxel = new VFVoxel(VFVoxel.ToNormByte((bpos >= coreVolume) ? coreVolume : (bpos % coreVolume)), voxelType);
                        AlterVoxel(px, py, pz, voxel, writeType, true);
                    }
                }
            }
        }
    }
Ejemplo n.º 7
0
    bool CheckVoxel(IntVector3 pos)
    {
        VFVoxel voxel = VFVoxelTerrain.self.Voxels.SafeRead(pos.x, pos.y, pos.z, 0);

        if (voxel.Volume < BSMath.MC_ISO_VALUE)
        {
            for (int axis = 0; axis < 3; axis++)
            {
                for (int adder = -1; adder <= 1; adder += 2)
                {
                    IntVector3 borderPos   = pos + new IntVector3(adder * ((axis == 0)?1:0), adder * ((axis == 1)?1:0), adder * ((axis == 2)?1:0));
                    VFVoxel    borderVoxel = VFVoxelTerrain.self.Voxels.SafeRead(borderPos.x, borderPos.y, borderPos.z, 0);
                    if (borderVoxel.Volume >= BSMath.MC_ISO_VALUE)
                    {
                        return(true);
                    }
                }
            }
        }
        else
        {
            return(true);
        }

        return(false);
    }
Ejemplo n.º 8
0
        //yang 处理土地
        public ISkillTarget GetTerrainTarget(Vector3 normal, Vector3 point)
        {
            IntVector3   fVoxelCenterPos;
            VFVoxel      voxel  = GetRaycastHitVoxel(normal, point, out fVoxelCenterPos);
            ISkillTarget target = new VFTerrainTarget(point, fVoxelCenterPos, ref voxel);

            return(target);
        }
Ejemplo n.º 9
0
    public DHElem(byte vol, byte type)
    {
        int len = vData.Length;

        for (int i = 0; i < len; i++)
        {
            vData[i] = new VFVoxel(vol, type);
        }
    }
Ejemplo n.º 10
0
    public static void ApplyVoxelVolume(IntVector3 digPos, IntVector3 chunkPos, VFVoxel voxel)
    {
        if (!Instance.VoxelVolumes.ContainsKey(chunkPos))
        {
            Instance.VoxelVolumes[chunkPos] = new Dictionary <IntVector3, VFVoxel>();
        }

        Instance.VoxelVolumes[chunkPos][digPos] = new VFVoxel(voxel.Volume, voxel.Type);
    }
Ejemplo n.º 11
0
    public VFVoxel GetRaycastHitVoxel(RaycastHit hitInfo, out IntVector3 voxelPos)
    {
        //(hitInfo.point - transform.localPosition) / VoxelTerrainConstants._scale;
        Vector3 vPos = hitInfo.point;

        if (0.05f > Mathf.Abs(hitInfo.normal.normalized.x))
        {
            vPos.x = Mathf.RoundToInt(vPos.x);
        }
        else
        {
            vPos.x = (hitInfo.normal.x > 0)?Mathf.Floor(vPos.x):Mathf.Ceil(vPos.x);
        }
        if (0.05f > Mathf.Abs(hitInfo.normal.normalized.y))
        {
            vPos.y = Mathf.RoundToInt(vPos.y);
        }
        else
        {
            vPos.y = (hitInfo.normal.y > 0)?Mathf.Floor(vPos.y):Mathf.Ceil(vPos.y);
        }
        if (0.05f > Mathf.Abs(hitInfo.normal.normalized.z))
        {
            vPos.z = Mathf.RoundToInt(vPos.z);
        }
        else
        {
            vPos.z = (hitInfo.normal.z > 0)?Mathf.Floor(vPos.z):Mathf.Ceil(vPos.z);
        }

        voxelPos = new Vector3(Mathf.Round(vPos.x), Mathf.Round(vPos.y), Mathf.Round(vPos.z));
#if false               //VOXEL_OFFSET
        voxelPos.x += 1;
        voxelPos.y += 1;
        voxelPos.z += 1;
#endif
        VFVoxel voxel = VFVoxelTerrain.self.Voxels.SafeRead(voxelPos.x, voxelPos.y, voxelPos.z);
        float   dis   = 0;
        while (voxel.Volume == 0)
        {
            dis += 0.1f;
            if (dis > 1.5f)
            {
                break;
            }
            Vector3 hitPoint = hitInfo.point - hitInfo.normal * dis;
            voxelPos = new Vector3(Mathf.Round(hitPoint.x), Mathf.Round(hitPoint.y), Mathf.Round(hitPoint.z));
#if false                       // VOXEL_OFFSET
            voxelPos.x += 1;
            voxelPos.y += 1;
            voxelPos.z += 1;
#endif
            voxel = VFVoxelTerrain.self.Voxels.SafeRead(voxelPos.x, voxelPos.y, voxelPos.z);
        }
        return(voxel);
    }
Ejemplo n.º 12
0
    // Note: now this function is invoked to mod/dig terrain
    public void AlterVoxelInBuild(int vx, int vy, int vz, VFVoxel voxel)
    {
        Voxels.SafeWrite(vx, vy, vz, voxel);
        int n = Voxels.DirtyChunkList.Count;

        for (int i = 0; i < n; i++)
        {
            SaveLoad.AddChunkToSaveList(Voxels.DirtyChunkList[i]);
        }
    }
Ejemplo n.º 13
0
    public BSVoxel Add(BSVoxel voxel, int x, int y, int z, int lod = 0)
    {
        VFVoxel old_voxel = VFVoxelTerrain.self.Voxels.Read(x, y, z, lod);

        voxel.volmue = (byte)Mathf.Clamp(old_voxel.Volume + voxel.volmue, 0, 255);

        VFVoxelTerrain.self.Voxels.Write(x, y, z, voxel.ToVoxel(), lod);

        return(voxel);
    }
Ejemplo n.º 14
0
 public bool SafeWrite(int x, int y, int z, VFVoxel voxel, int lod = 0)
 {
     if (x < 0 || x >= m_ChunkNumX << SHIFT ||
         y < 0 || y >= m_ChunkNumY << SHIFT ||
         z < 0 || z >= m_ChunkNumZ << SHIFT)
     {
         return(false);
     }
     Write(x, y, z, voxel, 0, false);
     return(true);
 }
Ejemplo n.º 15
0
    public BSVoxel Subtract(BSVoxel voxel, int x, int y, int z, int lod = 0)
    {
        VFVoxel old_voxel = VFVoxelTerrain.self.Voxels.Read(x, y, z, lod);
        VFVoxel new_voxel = new VFVoxel(old_voxel.Volume, old_voxel.Type);

        new_voxel.Volume = (byte)Mathf.Clamp(old_voxel.Volume - voxel.volmue, 0, 255);

        VFVoxelTerrain.self.AlterVoxelInBuild(x, y, z, new_voxel);

        return(voxel);
    }
Ejemplo n.º 16
0
    public bool SafeWrite(int x, int y, int z, VFVoxel voxel, int lod = 0)
    {
        if (x < 0 || x >= (_chunkNumX << VoxelTerrainConstants._shift) ||
            y < 1 || y >= (_chunkNumY << VoxelTerrainConstants._shift) ||
            z < 0 || z >= (_chunkNumZ << VoxelTerrainConstants._shift))
        {
            return(false);
        }

        Write(x, y, z, voxel, lod);
        return(true);
    }
Ejemplo n.º 17
0
    public void AlterVoxelListInChunk(List <IntVector3> intPos, float durDec)
    {
        float   tmpDur = Mathf.Clamp(durDec, 0, 255);
        VFVoxel _voxel = new VFVoxel((byte)tmpDur, 0);

        int n = intPos.Count;

        for (int i = 0; i < n; i++)
        {
            IntVector3 pos = intPos[i];
            AlterVoxelInChunk(pos.x, pos.y, pos.z, _voxel, true, true);
        }
    }
Ejemplo n.º 18
0
        VFVoxel GetRaycastHitVoxel(Vector3 normal, Vector3 point, out IntVector3 voxelPos)
        {
            Vector3 vPos = point;

            if (0.05f > Mathf.Abs(normal.normalized.x))
            {
                vPos.x = Mathf.RoundToInt(vPos.x);
            }
            else
            {
                vPos.x = (normal.x > 0)?Mathf.Floor(vPos.x):Mathf.Ceil(vPos.x);
            }
            if (0.05f > Mathf.Abs(normal.normalized.y))
            {
                vPos.y = Mathf.RoundToInt(vPos.y);
            }
            else
            {
                vPos.y = (normal.y > 0)?Mathf.Floor(vPos.y):Mathf.Ceil(vPos.y);
            }
            if (0.05f > Mathf.Abs(normal.normalized.z))
            {
                vPos.z = Mathf.RoundToInt(vPos.z);
            }
            else
            {
                vPos.z = (normal.z > 0)?Mathf.Floor(vPos.z):Mathf.Ceil(vPos.z);
            }

            voxelPos = new Vector3(Mathf.Round(vPos.x), Mathf.Round(vPos.y), Mathf.Round(vPos.z));
#if false               //VOXEL_OFFSET
            voxelPos.x += 1;
            voxelPos.y += 1;
            voxelPos.z += 1;
#endif
            VFVoxel voxel = VFVoxelTerrain.self.Voxels.SafeRead(voxelPos.x, voxelPos.y, voxelPos.z);
            float   dis   = 0;
            while (voxel.Volume == 0)
            {
                dis += 0.1f;
                Vector3 hitPoint = point - normal * dis;
                voxelPos = new Vector3(Mathf.Round(hitPoint.x), Mathf.Round(hitPoint.y), Mathf.Round(hitPoint.z));
#if false                       // VOXEL_OFFSET
                voxelPos.x += 1;
                voxelPos.y += 1;
                voxelPos.z += 1;
#endif
                voxel = VFVoxelTerrain.self.Voxels.SafeRead(voxelPos.x, voxelPos.y, voxelPos.z);
            }
            return(voxel);
        }
Ejemplo n.º 19
0
    public void AlterVoxel(int vx, int vy, int vz, VFVoxel voxel, bool writeType, bool writeVolume)
    {
        // Tip: Switch between Voxels.Read and Voxels.SafeRead (with bounds check) to enabled/disable falling through the world.

        VFVoxel existingVoxel = Voxels.SafeRead(vx, vy, vz);

        if (existingVoxel.Volume < VoxelTerrainConstants._isolevel)
        {
            existingVoxel.Volume = 0;
        }

        Voxels.SafeWrite(vx, vy, vz, new VFVoxel((byte)Mathf.Clamp((int)existingVoxel.Volume + (writeVolume ? (int)voxel.Volume : 0), 0, 255),
                                                 writeType ? voxel.Type : existingVoxel.Type));
    }
Ejemplo n.º 20
0
    public static void OutputTownVoxel(int x, int y, int z, VCVoxel voxel, VArtifactUnit town)
    {
        IntVector3 pos     = new IntVector3(x, y, z);
        VFVoxel    vfvoxel = new VFVoxel();

        vfvoxel.Type   = voxel.Type;
        vfvoxel.Volume = voxel.Volume;
        if (town.townVoxel.ContainsKey(pos))
        {
            VFVoxel originVoxel = town.townVoxel[pos];
            vfvoxel.Volume = (byte)Mathf.Clamp(vfvoxel.Volume + originVoxel.Volume, 0, 255);
        }
        town.townVoxel[pos] = vfvoxel;
        //Debug.LogError("addarttown:"+pos);
    }
Ejemplo n.º 21
0
        //public void RunEff(EffSkillInstance inst, ISkillTarget target)
        //{
        //	// Stand alone and client mine should check target, client proxy should not
        //	if (!GameConfig.IsMultiMode)
        //	{
        //		if (!inst.m_data.CheckTargetsValid(this, target))
        //		{
        //			// TODO : a warning message of not target in scope
        //			return;
        //		}
        //	}

        //	if (GameConfig.IsMultiMode)
        //	{
        //		ESkillTargetType type = target.GetTargetType();
        //		switch (type)
        //		{
        //		case ESkillTargetType.TYPE_SkillRunner:
        //			{
        //				SkillRunner ta = target as SkillRunner;
        //				if (null != ta)
        //					RPC("RPC_C2S_SkillCast", inst.m_data.m_id, ta.OwnerNetworkView.viewID);
        //			}
        //			break;
        //		}
        //	}

        //	inst.m_timeStartPrep = Time.time;
        //	inst.m_runner = new CoroutineStoppable(this, inst.m_data.Exec(this, target, inst));
        //	inst.m_sharedRunner = new CoroutineStoppable(this, inst.m_data.SharingCooling(this, inst));
        //}

        //public void RunEffOnProxy(EffSkillInstance inst, ISkillTarget target)
        //{
        //	// Stand alone and client mine should check target, client proxy should not
        //	if (!GameConfig.IsMultiMode)
        //	{
        //		if (!inst.m_data.CheckTargetsValid(this, target))
        //		{
        //			// TODO : a warning message of not target in scope
        //			return;
        //		}
        //	}

        //	inst.m_timeStartPrep = Time.time;
        //	inst.m_runner = new CoroutineStoppable(this, inst.m_data.Exec(this, target, inst));
        //	inst.m_sharedRunner = new CoroutineStoppable(this, inst.m_data.SharingCooling(this, inst));
        //}

        public ISkillTarget GetTargetByGameObject(RaycastHit hitinfo, EffSkillInstance inst)
        {
            ISkillTarget target = null;
            GameObject   obj    = hitinfo.collider.gameObject;

            if (obj != null)
            {
                int layer = obj.layer;
                switch (layer)
                {
                //VFVoxelTerrain
                case 12:
                {
                    //VFVoxelChunkGo chunk;
                    if ((obj.GetComponent <VFVoxelChunkGo>()) != null)
                    {
                        Vector3 fCurPos = hitinfo.point;
                        Vector3 vPos    = fCurPos / VoxelTerrainConstants._scale;

                        vPos += -Vector3.up * 0.01f;

                        IntVector3 fVoxelCenterPos = new IntVector3(Mathf.FloorToInt(vPos.x + 1), Mathf.FloorToInt(vPos.y + 1), Mathf.FloorToInt(vPos.z + 1));

                        VFVoxel voxel = VFVoxelTerrain.self.Voxels.SafeRead(fVoxelCenterPos.x, fVoxelCenterPos.y, fVoxelCenterPos.z);
                        target = new VFTerrainTarget(hitinfo.point, fVoxelCenterPos, ref voxel);
                    }
                }
                break;

                //Player
                case 10:
                {
                    target = obj.GetComponent <SkillRunner>();
                }
                break;
                }
            }

            if (!inst.m_data.CheckTargetsValid(this, target))
            {
                // TODO : a warning message of not target in scope
                return(null);
            }

            return(target);
        }
Ejemplo n.º 22
0
        public float FluidDisplacement(Vector3 wpos)
        {
            if (VFVoxelWater.self != null && VFVoxelWater.self.Voxels != null)
            {
                int x = Mathf.RoundToInt(wpos.x);
                int z = Mathf.RoundToInt(wpos.z);

                float   base_y = Mathf.Floor(wpos.y - 0.5f) + 0.5f;
                float   bias_y = wpos.y - base_y;
                int     y0     = Mathf.FloorToInt(base_y) + 1;
                int     y1     = y0 + 1;
                VFVoxel voxel0 = VFVoxelWater.self.Voxels.SafeRead(x, y0, z);
                VFVoxel voxel1 = VFVoxelWater.self.Voxels.SafeRead(x, y1, z);
                return(Mathf.Clamp01(Mathf.Lerp((float)voxel0.Volume, (float)voxel1.Volume, bias_y) / 255.0f));
            }
            return(0);
        }
Ejemplo n.º 23
0
    void OnDigTerrain(IntVector3 pos)
    {
#if NEW_CLOD_MGR
        foreach (KeyValuePair <int, CSCreator> kvp in m_Creators)
        {
            CSMgCreator mgCreator = kvp.Value as CSMgCreator;
            if (mgCreator == null)
            {
                continue;
            }

            mgCreator.m_Clod.DeleteClod(pos);
            VFVoxel voxel = VFVoxelTerrain.self.Voxels.SafeRead(pos.x, pos.y - 1, pos.z);
            if ((voxel.Type == PlantConst.DIRTY_TYPE0 || voxel.Type == PlantConst.DIRTY_TYPE1) && voxel.Volume > 128)
            {
                RaycastHit rch;
                if (Physics.Raycast(pos, Vector3.down, out rch, 2, 1 << Pathea.Layer.VFVoxelTerrain))
                {
                    mgCreator.m_Clod.AddClod(rch.point, false);
                }
                else
                {
                    mgCreator.m_Clod.AddClod(new Vector3(pos.x, pos.y - 0.7f, pos.z), false);
                }
            }
        }
#else
        CSClodMgr.DeleteClod(pos);

        VFVoxel voxel = VFVoxelTerrain.self.Voxels.SafeRead(pos.x, pos.y - 1, pos.z);
        if (voxel.Type == CSClodMgr.TerrainType)
        {
            RaycastHit rch;
            if (Physics.Raycast(pos, Vector3.down, out rch, 2, 1 << Pathea.Layer.VFVoxelTerrain))
            {
                CSClodMgr.AddClod(rch.point, false);
            }
            else
            {
                CSClodMgr.AddClod(new Vector3(pos.x, pos.y - 0.7f, pos.z), false);
            }
        }
#endif
    }
Ejemplo n.º 24
0
    bool checkTerrain(Vector3 pos)
    {
        VFVoxel voxel = VFVoxelTerrain.self.Voxels.SafeRead(Mathf.RoundToInt(pos.x), Mathf.FloorToInt(pos.y), Mathf.RoundToInt(pos.z));

        Collider[] cols = Physics.OverlapSphere(transform.position, 0.2f, -1 ^ (1 << Pathea.Layer.VFVoxelTerrain));
        foreach (Collider col in cols)
        {
            if (!col.isTrigger)
            {
                return(false);
            }
        }

        if (voxel.Type == 19 || voxel.Type == 63)
        {
            return(true);
        }
        return(false);
    }
Ejemplo n.º 25
0
        void DestroyTerrian()
        {
            VFVoxel vol = new VFVoxel((byte)0, 0);

            for (int i = 17; i <= 20; i++)
            {
                for (int j = 10; j <= 13; j++)
                {
                    VFVoxelTerrain.self.Voxels.SafeWrite(i, 1, j, vol);
                }
            }
            for (int i = 10; i <= 13; i++)
            {
                for (int j = 2; j <= 5; j++)
                {
                    VFVoxelTerrain.self.Voxels.SafeWrite(i, j, 9, vol);
                }
            }
        }
Ejemplo n.º 26
0
    void RPC_S2C_Plant_VFTerrainTarget(uLink.BitStream stream, uLink.NetworkMessageInfo info)
    {
        byte[] data = stream.Read <byte[]> ();
        /*int viewId = */ stream.Read <int> ();
        //if ( PlayerFactory.mMainPlayer.OwnerView.viewID.id == viewId )
        //    return;
        MemoryStream ms   = new MemoryStream(data);
        BinaryReader _out = new BinaryReader(ms);

        Dictionary <IntVector3, VFVoxel> voxels = new Dictionary <IntVector3, VFVoxel> ();
        int Count = _out.ReadInt32();

        for (int i = 0; i < Count; i++)
        {
            IntVector3 index = new IntVector3(_out.ReadInt32(), _out.ReadInt32(), _out.ReadInt32());
            voxels [index] = new VFVoxel(_out.ReadByte(), _out.ReadByte());
            VFVoxelTerrain.self.AlterVoxelInBuild(index.ToVector3(), voxels [index]);
        }
    }
Ejemplo n.º 27
0
    public bool SafeWrite(int x, int y, int z, VFVoxel voxel, int lod = 0)
    {
#if false       // Inifinit terrain's xz may be any number.
        if (x < 0 || x >= VoxelTerrainConstants._worldSideLenX ||
            y < 1 || y >= VoxelTerrainConstants._worldSideLenY ||
            z < 0 || z >= VoxelTerrainConstants._worldSideLenZ)
        {
            return(false);
        }
#else
        if (y < 1)
        {
            return(false);              //Keep the very ground
        }
#endif

        Write(x, y, z, voxel, lod);
        return(true);
    }
Ejemplo n.º 28
0
    public void AlterVoxelBox(int x, int y, int z, int width, int height, int depth, float volume, byte voxelType, bool writeType)
    {
        int x1 = x - width / 2;
        int y1 = y - height / 2;
        int z1 = z - depth / 2;
        int x2 = x + width / 2;
        int y2 = y + height / 2;
        int z2 = z + depth / 2;

        for (int px = x1; px < x2; ++px)
        {
            for (int py = y1; py < y2; ++py)
            {
                for (int pz = z1; pz < z2; ++pz)
                {
                    VFVoxel voxel = new VFVoxel(VFVoxel.ToNormByte(volume), voxelType);
                    AlterVoxel(px, py, pz, voxel, writeType, true);
                }
            }
        }
    }
Ejemplo n.º 29
0
    void OnChunkAddedEvent(object sender, EventArgs args)
    {
        if (null == VFVoxelTerrain.self)
        {
            return;
        }

        ChunkEventArgs chunkArgs = args as ChunkEventArgs;
        IntVector3     chunkPos  = new IntVector3(chunkArgs._pos.x, chunkArgs._pos.y, chunkArgs._pos.z);

        if (VoxelVolumes.ContainsKey(chunkPos))
        {
            foreach (KeyValuePair <IntVector3, VFVoxel> kv in VoxelVolumes[chunkPos])
            {
                VFVoxel voxel = VFVoxelTerrain.self.Voxels.SafeRead(kv.Key.x, kv.Key.y, kv.Key.z);
                voxel.Volume = kv.Value.Volume;
                voxel.Type   = kv.Value.Type;
                VFVoxelTerrain.self.AlterVoxelInBuild(kv.Key, voxel);
            }
        }
    }
Ejemplo n.º 30
0
    public void SafeCheckVelocity(PhysicsCharacterMotor rigidbody)
    {
        Vector3 pos = rigidbody.transform.position;

        if (pos.y < 0)
        {
            rigidbody.transform.position = pos - pos.y * Vector3.up;
            return;
        }

        if (IsPosInGenerating(ref pos))
        {
            rigidbody.FreezeGravity = true;
        }
        else         //if(!rigidbody.grounded)
        {
            rigidbody.FreezeGravity = false;
            float      upRayLen       = 1500.0f;
            float      dnRayLen       = 400.0f;
            int        vfterrainLayer = Pathea.Layer.VFVoxelTerrain;
            RaycastHit hit;
            if (Physics.Raycast(pos + Vector3.up * upRayLen, Vector3.down, out hit, upRayLen - 0.1f, 1 << vfterrainLayer))
            {
                // Add check if part of player is under terrain, may cause player jump up out of cave
                if (pos.y >= hit.point.y - 1.5f || !Physics.Raycast(pos + Vector3.up, Vector3.down, dnRayLen, 1 << vfterrainLayer))
                {
                    VFVoxel voxel = VFVoxelTerrain.self.Voxels.SafeRead((int)pos.x, (int)pos.y, (int)pos.z);
                    if (0 != voxel.Type && voxel.Volume > 127)
                    {
                        voxel = VFVoxelTerrain.self.Voxels.SafeRead((int)pos.x, (int)pos.y - 1, (int)pos.z);
                        if (0 != voxel.Type && voxel.Volume > 127)
                        {
                            Debug.Log("PlayerFallenCheckFix");
                            rigidbody.transform.position = hit.point;
                        }
                    }
                }
            }
        }
    }