Ejemplo n.º 1
0
        //CONSIDER: we will want to define this class's relationship to Chunk at some point

        public void Init(IntVector3 chunkPos, uint[] voxels)
        {
            int depth = vGenConfig.hilbertBits;

            Vector3 center = vGenConfig.ChunkPosToPos(chunkPos) + vGenConfig.ChunkSize / 2f;
            var     bounds = new Bounds(center, vGenConfig.ChunkSize);

            tree = new VoxelOctree <uint>(depth, bounds);

            foreach (uint vox in voxels)
            {
                IntVector3 pos = IntVector3.FromUint256(vox);
                tree.Set(vox, pos.ToVector3());
            }

            // instantiate or just set up raycast display
            rayDisplay = Instantiate(raycastDisplayPrefab);
            rayDisplay.transform.SetParent(transform);
            rayDisplay.transform.localPosition = vGenConfig.ChunkPosToPos(chunkPos);

            //ComputeBuffer b = BufferUtil.CreateWith(voxels);

            rayDisplay.initialize(null);
            //ResetBufferData(voxels); //test


            StartCoroutine(Scan()); //want
        }
Ejemplo n.º 2
0
        void UpdateNearList()
        {
            m_nearList.Clear();

            var eye     = m_camera.Position;
            var frustum = m_camera.Frustum;

            var farCorner = GetFrustumFarthestCorner(ref frustum);

            float camRadius = (farCorner - eye).Length();

            float chunkRadius = (float)Math.Sqrt(3) * Chunk.CHUNK_SIZE / 2;

            var viewGrid = m_viewGridProvider.ViewGrid;

            // XXX grid can be reduced to be inside camradius, but we need to somehow free the chunks that go outside near list
            //var grid = new IntGrid3(viewGrid.Corner1 / Chunk.CHUNK_SIZE, (viewGrid.Corner2 + Chunk.CHUNK_SIZE - 1) / Chunk.CHUNK_SIZE);
            var grid = this.Size;

            foreach (var cp in grid.Range())
            {
                var chunk = GetChunk(cp);

                IntVector3 chunkOffset = cp * Chunk.CHUNK_SIZE;

                var chunkGrid = new IntGrid3(chunkOffset, Chunk.ChunkSize);

                var containment = viewGrid.ContainsExclusive(ref chunkGrid);

                if (containment == Containment.Disjoint)
                {
                    // the chunk is outside the view area
                    if (chunk != null)
                    {
                        FreeChunk(chunk);
                    }
                    continue;
                }

                var chunkCenter = chunkOffset.ToVector3() + new Vector3(Chunk.CHUNK_SIZE / 2);

                if (Vector3.Distance(eye, chunkCenter) - chunkRadius > camRadius)
                {
                    if (chunk != null)
                    {
                        FreeChunk(chunk);
                    }
                    continue;
                }

                if (chunk == null)
                {
                    chunk = CreateChunk(cp);
                }

                m_nearList.Add(chunk);
            }

            m_forceDrawListUpdate = true;
        }
Ejemplo n.º 3
0
        public void CameraLookAt(IntVector3 p)
        {
            var eye    = GetEyeFromLookTarget(p);
            var target = p.ToVector3();

            this.Camera.LookAt(eye, target, Vector3.UnitZ);
        }
Ejemplo n.º 4
0
        public void CameraMoveTo(IntVector3 p)
        {
            var eye    = GetEyeFromLookTarget(p);
            var target = p.ToVector3();

            this.CameraMoveService.Move(eye, target);
        }
Ejemplo n.º 5
0
 public void Initialise(IntVector3 position)
 {
     base.Initialise(GameManager.Instance.ChunkPrefab);
     Position = position;
     GameObject.name = "ChunkEntity " + Position;
     GameObject.transform.position = position.ToVector3();
     MeshFilter = GameObject.GetComponent<MeshFilter>();
 }
Ejemplo n.º 6
0
    protected override void Do()
    {
        m_Action = new VCEAction();

        ulong oldmat_guid = VCEditor.s_Scene.m_IsoData.MaterialGUID(VCEditor.SelectedVoxelType);
        ulong newmat_guid = VCEditor.SelectedMaterial.m_Guid;

        if (oldmat_guid != newmat_guid)
        {
            VCEAlterMaterialMap modify = new VCEAlterMaterialMap(VCEditor.SelectedVoxelType, oldmat_guid, newmat_guid);
            m_Action.Modifies.Add(modify);
        }

        IntVector3 draw = m_Target.cursor + m_Offset;

        // Mirror
        if (VCEditor.s_Mirror.Enabled_Masked)
        {
            VCEditor.s_Mirror.CalcPrepare(VCEditor.s_Scene.m_Setting.m_VoxelSize);
            VCEditor.s_Mirror.MirrorVoxel(draw);

            for (int i = 0; i < VCEditor.s_Mirror.OutputCnt; ++i)
            {
                if (VCEditor.s_Scene.m_IsoData.IsPointIn(VCEditor.s_Mirror.Output[i]))
                {
                    int     voxel_pos = VCIsoData.IPosToKey(VCEditor.s_Mirror.Output[i]);
                    VCVoxel old_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(voxel_pos);
                    VCVoxel new_voxel = new VCVoxel(255, (byte)VCEditor.SelectedVoxelType);
                    if (old_voxel != new_voxel)
                    {
                        VCEAlterVoxel modify = new VCEAlterVoxel(voxel_pos, old_voxel, new_voxel);
                        m_Action.Modifies.Add(modify);
                    }
                }
            }
        }
        // No mirror
        else
        {
            int     voxel_pos = VCIsoData.IPosToKey(draw);
            VCVoxel old_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(voxel_pos);
            VCVoxel new_voxel = new VCVoxel(255, (byte)VCEditor.SelectedVoxelType);
            if (old_voxel != new_voxel)
            {
                VCEAlterVoxel modify = new VCEAlterVoxel(voxel_pos, old_voxel, new_voxel);
                m_Action.Modifies.Add(modify);
            }
        }
        if (m_Action.Modifies.Count > 0)
        {
            m_Action.Do();
        }

        VCEditor.Instance.m_MainCamera.GetComponent <VCECamera>().SetTarget(
            (draw.ToVector3() + Vector3.one * 0.5f) * VCEditor.s_Scene.m_Setting.m_VoxelSize);
    }
Ejemplo n.º 7
0
        void SetWorlMatrix(IntVector3 pos, IntSize3 size, Direction dir)
        {
            var worldMatrix = Matrix.Identity;

            worldMatrix.Transpose();

            worldMatrix *= Matrix.Translation(new Vector3(-0.5f));
            worldMatrix *= Matrix.RotationQuaternion(s_rotationQuaternions[(int)dir.ToDirectionOrdinal()]);
            worldMatrix *= Matrix.Scaling(size.Width, size.Height, size.Depth);
            worldMatrix *= Matrix.Scaling(new Vector3(0.01f) / size.ToIntVector3().ToVector3() + 1);             // fix z fight
            worldMatrix *= Matrix.Translation(new Vector3(0.5f));
            worldMatrix *= Matrix.Translation((size.ToIntVector3().ToVector3() - new Vector3(1)) / 2);
            worldMatrix *= Matrix.Translation(pos.ToVector3());

            m_effect.Parameters["worldMatrix"].SetValue(ref worldMatrix);
        }
Ejemplo n.º 8
0
        bool ResolvePaintPosition(ref Ray ray, ref IntVector3 brushPosition)
        {
            var brushPositionWorld = brushPosition.ToVector3();

            Matrix world;

            Matrix.CreateTranslation(ref brushPositionWorld, out world);

            var rayDirection = ray.Direction;

            rayDirection.Normalize();

            for (int i = 0; i < triangleInfos.Length; i++)
            {
                var side = triangleInfos[i].Side;

                // 面固定済みならば、それ以外の面を除外。
                if (PaintStarted && lockedSide != null && side != lockedSide)
                {
                    continue;
                }

                // 背面は判定から除外。
                if (IsBackFace(side, ref rayDirection))
                {
                    continue;
                }

                // 面と視線が交差するか否か。
                if (Intersects(ref ray, triangleInfos[i], ref world))
                {
                    var testPosition = brushPosition + side.Direction;
                    var blockIndex   = Manager.GetBlockIndex(ref testPosition);
                    if (blockIndex == Block.EmptyIndex)
                    {
                        PaintPosition = testPosition;
                        paintSide     = side;
                        return(true);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 9
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.º 10
0
    public List <TreeInfo> TreesAtPos(IntVector3 pos)
    {
        treelist.Clear();
        int      X = Mathf.FloorToInt(pos.x / RSubTerrConstant.ChunkSizeF);
        int      Z = Mathf.FloorToInt(pos.z / RSubTerrConstant.ChunkSizeF);
        TreeInfo tmpTi;

        for (int x = X - 1; x <= X + 1; ++x)
        {
            for (int z = Z - 1; z <= Z + 1; ++z)
            {
                int idx     = RSubTerrUtils.ChunkPosToIndex(x, z);
                int treeidx = RSubTerrUtils.TreeWorldPosToChunkIndex(pos.ToVector3(), idx);
                if (m_Chunks.ContainsKey(idx) && m_Chunks[idx].m_mapTrees.TryGetValue(treeidx, out tmpTi))
                {
                    TreeInfo.AddTiToList(treelist, tmpTi);
                }
            }
        }
        return(treelist);
    }
Ejemplo n.º 11
0
        public Rect GetPlacementRect(IntVector3 ml)
        {
            // XXX
            var view = m_game.Surfaces[0].Views[0];

            SharpDX.Matrix matrix = view.Camera.View * view.Camera.Projection;

            var p1 = ml.ToVector3();
            var p2 = p1 + new SharpDX.Vector3(1, 1, 0);

            SharpDX.Vector3 out1, out2;

            var vp = view.ViewPort;

            vp.Project(ref p1, ref matrix, out out1);
            vp.Project(ref p2, ref matrix, out out2);

            Rect rect = new Rect(
                DeviceToPoint(new System.Windows.Point(out1.X, out1.Y)),
                DeviceToPoint(new System.Windows.Point(out2.X, out2.Y)));

            return(rect);
        }
Ejemplo n.º 12
0
    protected static Vector3 CalcCursor(BSMath.DrawTarget target, IBSDataSource ds, int size)
    {
        Vector3    cursor  = Vector3.zero;
        IntVector3 realPos = new IntVector3(Mathf.FloorToInt(target.cursor.x * ds.ScaleInverted),
                                            Mathf.FloorToInt(target.cursor.y * ds.ScaleInverted),
                                            Mathf.FloorToInt(target.cursor.z * ds.ScaleInverted));

        float offset = Mathf.FloorToInt(size * 0.5f) * ds.Scale;


        cursor = realPos.ToVector3() * ds.Scale - new Vector3(offset, offset, offset);
        int sign = size % 2 == 0? 1 : 0;

        if (offset != 0)
        {
            Vector3 offset_v = Vector3.zero;

            if (target.rch.normal.x > 0)
            {
                offset_v.x += offset;
            }
            else if (target.rch.normal.x < 0)
            {
                offset_v.x -= (offset - ds.Scale * sign);
            }
            else
            {
                offset_v.x = 0;
            }

            if (target.rch.normal.y > 0)
            {
                offset_v.y += offset;
            }
            else if (target.rch.normal.y < 0)
            {
                offset_v.y -= (offset - ds.Scale * sign);
            }

            else
            {
                offset_v.y = 0;
            }

            if (target.rch.normal.z > 0)
            {
                offset_v.z += offset;
            }
            else if (target.rch.normal.z < 0)
            {
                offset_v.z -= (offset - ds.Scale * sign);
            }
            else
            {
                offset_v.z = 0;
            }

            cursor += offset_v;
        }

        return(cursor);
    }
Ejemplo n.º 13
0
        static void HandleTree(VertexList <SceneryVertex> sceneryVertexList, TileData td, ref IntVector3 pos)
        {
            SymbolID symbol;
            Color    color;

            switch (td.ID)
            {
            case TileID.Tree:
                switch (td.MaterialID)
                {
                case MaterialID.Fir:
                    symbol = SymbolID.ConiferousTree;
                    break;

                case MaterialID.Pine:
                    symbol = SymbolID.ConiferousTree2;
                    break;

                case MaterialID.Birch:
                    symbol = SymbolID.DeciduousTree;
                    break;

                case MaterialID.Oak:
                    symbol = SymbolID.DeciduousTree2;
                    break;

                default:
                    throw new Exception();
                }
                break;

            case TileID.Sapling:
                switch (td.MaterialID)
                {
                case MaterialID.Fir:
                    symbol = SymbolID.ConiferousSapling;
                    break;

                case MaterialID.Pine:
                    symbol = SymbolID.ConiferousSapling2;
                    break;

                case MaterialID.Birch:
                    symbol = SymbolID.DeciduousSapling;
                    break;

                case MaterialID.Oak:
                    symbol = SymbolID.DeciduousSapling2;
                    break;

                default:
                    throw new Exception();
                }
                break;

            case TileID.DeadTree:
                symbol = SymbolID.DeadTree;
                break;

            default:
                throw new Exception();
            }

            color = Color.ForestGreen;

            sceneryVertexList.Add(new SceneryVertex(pos.ToVector3(), Color.LightGreen, (uint)symbol));
        }
Ejemplo n.º 14
0
    protected static Vector3 CalcSnapto(BSMath.DrawTarget target, IBSDataSource ds, BSPattern pt)
    {
        Vector3 snapto = Vector3.zero;
        // Update gizmo Position
        IntVector3 realPos = new IntVector3(Mathf.FloorToInt(target.snapto.x * ds.ScaleInverted),
                                            Mathf.FloorToInt(target.snapto.y * ds.ScaleInverted),
                                            Mathf.FloorToInt(target.snapto.z * ds.ScaleInverted));

        float offset = Mathf.FloorToInt(pt.size * 0.5f) * ds.Scale;

        snapto = realPos.ToVector3() * ds.Scale - new Vector3(offset, offset, offset);
        int sign = pt.size % 2 == 0? 1 : 0;

        if (offset != 0)
        {
            Vector3 offset_v = Vector3.zero;

            if (target.rch.normal.x > 0)
            {
                offset_v.x -= (offset - ds.Scale * sign);
            }
            else if (target.rch.normal.x < 0)
            {
                offset_v.x += offset;
            }
            else
            {
                offset_v.x = 0;
            }

            if (target.rch.normal.y > 0)
            {
                offset_v.y -= (offset - ds.Scale * sign);
            }
            else if (target.rch.normal.y < 0)
            {
                offset_v.y += offset;
            }

            else
            {
                offset_v.y = 0;
            }

            if (target.rch.normal.z > 0)
            {
                offset_v.z -= (offset - ds.Scale * sign);
            }
            else if (target.rch.normal.z < 0)
            {
                offset_v.z += offset;
            }
            else
            {
                offset_v.z = 0;
            }

            snapto += offset_v;
        }

        return(snapto);
    }
Ejemplo n.º 15
0
 public void SetPosition(IntVector3 position)
 {
     this.position           = position;
     transform.localPosition = position.ToVector3();
 }
Ejemplo n.º 16
0
        void SetWorlMatrix(IntVector3 pos, IntSize3 size, Direction dir)
        {
            var worldMatrix = Matrix.Identity;
            worldMatrix.Transpose();

            worldMatrix *= Matrix.Translation(new Vector3(-0.5f));
            worldMatrix *= Matrix.RotationQuaternion(s_rotationQuaternions[(int)dir.ToDirectionOrdinal()]);
            worldMatrix *= Matrix.Scaling(size.Width, size.Height, size.Depth);
            worldMatrix *= Matrix.Scaling(new Vector3(0.01f) / size.ToIntVector3().ToVector3() + 1); // fix z fight
            worldMatrix *= Matrix.Translation(new Vector3(0.5f));
            worldMatrix *= Matrix.Translation((size.ToIntVector3().ToVector3() - new Vector3(1)) / 2);
            worldMatrix *= Matrix.Translation(pos.ToVector3());

            m_effect.Parameters["worldMatrix"].SetValue(ref worldMatrix);
        }
Ejemplo n.º 17
0
    protected override void Do()
    {
        m_Action = new VCEAction();

        ulong oldmat_guid = VCEditor.s_Scene.m_IsoData.MaterialGUID(VCEditor.SelectedVoxelType);
        ulong newmat_guid = VCEditor.SelectedMaterial.m_Guid;

        if (oldmat_guid != newmat_guid)
        {
            VCEAlterMaterialMap modify = new VCEAlterMaterialMap(VCEditor.SelectedVoxelType, oldmat_guid, newmat_guid);
            m_Action.Modifies.Add(modify);
        }

        VCEditor.s_Mirror.CalcPrepare(VCEditor.s_Scene.m_Setting.m_VoxelSize);
        IntVector3 min           = Min;
        IntVector3 max           = Max;
        Vector3    extend        = Size.ToVector3() * 0.5f;
        Vector3    center        = min.ToVector3() + extend;
        Vector3    inv_scale     = Vector3.one;
        float      radius        = Mathf.Max(extend.x, extend.y, extend.z);
        float      min_dimension = Mathf.Max(Mathf.Min(extend.x, extend.y, extend.z) - 0.5f, 1);

        if (extend.x >= extend.y && extend.x >= extend.z)
        {
            inv_scale = new Vector3(1, extend.x / extend.y, extend.x / extend.z);
        }
        else if (extend.y >= extend.x && extend.y >= extend.z)
        {
            inv_scale = new Vector3(extend.y / extend.x, 1, extend.y / extend.z);
        }
        else
        {
            inv_scale = new Vector3(extend.z / extend.x, extend.z / extend.y, 1);
        }

        for (int x = min.x - 2; x <= max.x + 2; ++x)
        {
            for (int y = min.y - 2; y <= max.y + 2; ++y)
            {
                for (int z = min.z - 2; z <= max.z + 2; ++z)
                {
                    IntVector3 pos = new IntVector3(x, y, z);
                    // Mirror
                    if (VCEditor.s_Mirror.Enabled_Masked)
                    {
                        Vector3 sphere_coord = (pos.ToVector3() + Vector3.one * 0.5f) - center;
                        sphere_coord.x *= inv_scale.x;
                        sphere_coord.y *= inv_scale.y;
                        sphere_coord.z *= inv_scale.z;

                        float delta  = (radius - sphere_coord.magnitude) / radius;
                        float volume = Mathf.Clamp(delta * min_dimension * VCEMath.MC_ISO_VALUEF + VCEMath.MC_ISO_VALUEF, 0, 255.49f);

                        VCEditor.s_Mirror.MirrorVoxel(pos);

                        for (int i = 0; i < VCEditor.s_Mirror.OutputCnt; ++i)
                        {
                            pos = VCEditor.s_Mirror.Output[i];
                            if (VCEditor.s_Scene.m_IsoData.IsPointIn(pos))
                            {
                                int     voxel_pos = VCIsoData.IPosToKey(pos);
                                VCVoxel old_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(voxel_pos);
                                VCVoxel new_voxel = 0;
                                if (old_voxel.Volume == 0)
                                {
                                    new_voxel = new VCVoxel((byte)(volume), (byte)VCEditor.SelectedVoxelType);
                                }
                                else if (old_voxel.Volume < VCEMath.MC_ISO_VALUE)
                                {
                                    if (volume < VCEMath.MC_ISO_VALUE)
                                    {
                                        new_voxel = old_voxel;
                                    }
                                    else
                                    {
                                        new_voxel = new VCVoxel((byte)(volume), (byte)VCEditor.SelectedVoxelType);
                                    }
                                }
                                else
                                {
                                    if (volume < VCEMath.MC_ISO_VALUE)
                                    {
                                        new_voxel = old_voxel;
                                    }
                                    else
                                    {
                                        new_voxel = new VCVoxel((byte)(volume), (byte)VCEditor.SelectedVoxelType);
                                    }
                                }
                                VCVoxel old_st_voxel = VCEditor.s_Scene.m_Stencil.GetVoxel(voxel_pos);
                                new_voxel.Volume = (new_voxel.Volume > old_st_voxel.Volume) ? (new_voxel.Volume) : (old_st_voxel.Volume);
                                VCEditor.s_Scene.m_Stencil.SetVoxel(voxel_pos, new_voxel);
                            }
                        }
                    }
                    // No mirror
                    else
                    {
                        if (VCEditor.s_Scene.m_IsoData.IsPointIn(pos))
                        {
                            Vector3 sphere_coord = (pos.ToVector3() + Vector3.one * 0.5f) - center;
                            sphere_coord.x *= inv_scale.x;
                            sphere_coord.y *= inv_scale.y;
                            sphere_coord.z *= inv_scale.z;

                            float delta  = (radius - sphere_coord.magnitude) / radius;
                            float volume = Mathf.Clamp(delta * min_dimension * VCEMath.MC_ISO_VALUEF + VCEMath.MC_ISO_VALUEF, 0, 255.49f);

                            int     voxel_pos = VCIsoData.IPosToKey(pos);
                            VCVoxel old_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(voxel_pos);
                            VCVoxel new_voxel = 0;
                            if (old_voxel.Volume == 0)
                            {
                                new_voxel = new VCVoxel((byte)(volume), (byte)VCEditor.SelectedVoxelType);
                            }
                            else if (old_voxel.Volume < VCEMath.MC_ISO_VALUE)
                            {
                                if (volume < VCEMath.MC_ISO_VALUE)
                                {
                                    new_voxel = old_voxel;
                                }
                                else
                                {
                                    new_voxel = new VCVoxel((byte)(volume), (byte)VCEditor.SelectedVoxelType);
                                }
                            }
                            else
                            {
                                if (volume < VCEMath.MC_ISO_VALUE)
                                {
                                    new_voxel = old_voxel;
                                }
                                else
                                {
                                    new_voxel = new VCVoxel((byte)(volume), (byte)VCEditor.SelectedVoxelType);
                                }
                            }
                            VCEditor.s_Scene.m_Stencil.SetVoxel(voxel_pos, new_voxel);
                        }
                    }
                }
            }
        }
        VCEditor.s_Scene.m_Stencil.NormalizeAllVoxels();
        foreach (KeyValuePair <int, VCVoxel> kvp in VCEditor.s_Scene.m_Stencil.m_Voxels)
        {
            VCVoxel old_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(kvp.Key);
            VCVoxel new_voxel = VCEditor.s_Scene.m_Stencil.GetVoxel(kvp.Key);
            if (old_voxel != new_voxel)
            {
                VCEAlterVoxel modify = new VCEAlterVoxel(kvp.Key, old_voxel, new_voxel);
                m_Action.Modifies.Add(modify);
            }
        }
        VCEditor.s_Scene.m_Stencil.Clear();
        if (m_Action.Modifies.Count > 0)
        {
            m_Action.Do();
        }
        ResetDrawing();
    }
Ejemplo n.º 18
0
        public Rect GetPlacementRect(IntVector3 ml)
        {
            // XXX
            var view = m_game.Surfaces[0].Views[0];

            SharpDX.Matrix matrix = view.Camera.View * view.Camera.Projection;

            var p1 = ml.ToVector3();
            var p2 = p1 + new SharpDX.Vector3(1, 1, 0);
            SharpDX.Vector3 out1, out2;

            var vp = view.ViewPort;

            vp.Project(ref p1, ref matrix, out out1);
            vp.Project(ref p2, ref matrix, out out2);

            Rect rect = new Rect(
                DeviceToPoint(new System.Windows.Point(out1.X, out1.Y)),
                DeviceToPoint(new System.Windows.Point(out2.X, out2.Y)));

            return rect;
        }
Ejemplo n.º 19
0
    void Update()
    {
        if (VFVoxelTerrain.self == null)
        {
            return;
        }


        if (IsVoxel)
        {
//			Gizmo.transform.localScale = new Vector3(1, 1, 1);
            Gizmo.transform.localScale = new Vector3(BrushSize, BrushSize, BrushSize);
            m_Indicator.enabled        = true;
            m_BlockIndicator.enabled   = false;
        }
        else
        {
            m_Indicator.enabled        = false;
            m_BlockIndicator.enabled   = true;
            Gizmo.transform.localScale = new Vector3(0.5f * BrushSize, 0.5f * BrushSize, 0.5f * BrushSize);
            m_BlockIndicator.m_Expand  = 1 + BrushSize;
        }


        IBSDataSource ds = null;         //= IsVoxel ? BuildingMan.Voxels : BuildingMan.Blocks;
        BSVoxel       voxel;

        if (IsVoxel)
        {
            voxel        = new BSVoxel();
            voxel.value0 = 255;
            voxel.value1 = 2;
            ds           = BuildingMan.Voxels;
        }
        else
        {
            voxel        = new BSVoxel();
            voxel.value0 = B45Block.MakeBlockType(1, 0);
            voxel.value1 = 0;
            ds           = BuildingMan.Blocks;
        }


//		if (BSMath.RayCastDrawTarget(Camera.main.ScreenPointToRay( Input.mousePosition), out m_Target, BSMath.MC_ISO_VALUE, IsVoxel))
        if (BSMath.RayCastDrawTarget(Camera.main.ScreenPointToRay(Input.mousePosition),
                                     ds, out m_Target, BSMath.MC_ISO_VALUE, false, BuildingMan.Datas))
        {
            IntVector3 realPos = new IntVector3(Mathf.FloorToInt(m_Target.cursor.x * ds.ScaleInverted),
                                                Mathf.FloorToInt(m_Target.cursor.y * ds.ScaleInverted),
                                                Mathf.FloorToInt(m_Target.cursor.z * ds.ScaleInverted));

            float offset = Mathf.FloorToInt(BrushSize * 0.5f) * ds.Scale;
            //int xMultiplier = 0, yMultiplier = 0, zMultiplier = 0;


            Vector3 cursor = realPos.ToVector3() * ds.Scale - new Vector3(offset, offset, offset);
            int     sign   = BrushSize % 2 == 0? 1 : 0;

            if (offset != 0)
            {
                Vector3 offset_v = Vector3.zero;

                if (m_Target.rch.normal.x > 0)
                {
                    offset_v.x += offset;
                }
                else if (m_Target.rch.normal.x < 0)
                {
                    offset_v.x -= (offset - ds.Scale * sign);
                }
                else
                {
                    offset_v.x = 0;
                }

                if (m_Target.rch.normal.y > 0)
                {
                    offset_v.y += offset;
                }
                else if (m_Target.rch.normal.y < 0)
                {
                    offset_v.y -= (offset - ds.Scale * sign);
                }

                else
                {
                    offset_v.y = 0;
                }

                if (m_Target.rch.normal.z > 0)
                {
                    offset_v.z += offset;
                }
                else if (m_Target.rch.normal.z < 0)
                {
                    offset_v.z -= (offset - ds.Scale * sign);
                }
                else
                {
                    offset_v.z = 0;
                }

                cursor += offset_v;
            }



            Gizmo.transform.position = cursor + ds.Offset;

            if (Input.GetMouseButtonDown(0))
            {
                int cnt = BrushSize;

                for (int x = 0; x < cnt; x++)
                {
                    for (int y = 0; y < cnt; y++)
                    {
                        for (int z = 0; z < cnt; z++)
                        {
                            IntVector3 inpos = new IntVector3(Mathf.FloorToInt(cursor.x * ds.ScaleInverted) + x,
                                                              Mathf.FloorToInt(cursor.y * ds.ScaleInverted) + y,
                                                              Mathf.FloorToInt(cursor.z * ds.ScaleInverted) + z);

                            ds.Write(voxel, inpos.x, inpos.y, inpos.z);
                        }
                    }
                }
            }
//			if (IsVoxel)
//			{
////				Gizmo.transform.position = m_Target.cursor - Vector3.one * 0.5f;
////
////				if (Input.GetMouseButtonDown(0))
////				{
////					VFVoxel voxel = new VFVoxel(255, 2);
////					IntVector3 cursor = m_Target.iCursor;
////					VFVoxelTerrain.self.Voxels.Write(cursor.x, cursor.y, cursor.z, voxel);
////				}
//
//
//			}
//			else
//			{
//
//				IntVector3 realPos = new IntVector3( Mathf.FloorToInt(m_Target.cursor.x * Block45Constants._scaleInverted),
//				                                    Mathf.FloorToInt( m_Target.cursor.y  * Block45Constants._scaleInverted),
//				                                    Mathf.FloorToInt( m_Target.cursor.z * Block45Constants._scaleInverted));
//
//				float offset = Mathf.FloorToInt(BrushSize * 0.5f) * Block45Constants._scale;
//				int xMultiplier = 0, yMultiplier = 0, zMultiplier = 0;
//
//
//				Vector3 cursor = realPos.ToVector3() * Block45Constants._scale - new Vector3(offset, offset, offset);
//				int sign = BrushSize % 2 == 0? 1 : 0;
//
//				if (offset != 0)
//				{
//					Vector3 offset_v = Vector3.zero;
//
//					if (m_Target.rch.normal.x > 0)
//						offset_v.x += offset;
//					else if (m_Target.rch.normal.x < 0)
//						offset_v.x -= (offset - Block45Constants._scale * sign);
//					else
//						offset_v.x = 0;
//
//					if (m_Target.rch.normal.y > 0)
//						offset_v.y += offset;
//					else if (m_Target.rch.normal.y < 0)
//						offset_v.y -= (offset - Block45Constants._scale * sign);
//
//					else
//						offset_v.y = 0;
//
//					if (m_Target.rch.normal.z > 0)
//						offset_v.z += offset;
//					else if (m_Target.rch.normal.z < 0)
//						offset_v.z -=  (offset - Block45Constants._scale * sign);
//					else
//						offset_v.z = 0;
//
//					cursor += offset_v;
//				}
//
//
//
//				Gizmo.transform.position = cursor ;
//
//				if (Input.GetMouseButtonDown(0))
//				{
//					int cnt = BrushSize;
//
//					for (int x = 0; x < cnt; x++)
//					{
//						for (int y = 0; y < cnt; y++)
//						{
//							for (int z = 0; z < cnt; z++)
//							{
//								B45Block block = new B45Block(B45Block.MakeBlockType(1,0), 0);
//								IntVector3 inpos = new IntVector3(Mathf.FloorToInt( cursor.x * Block45Constants._scaleInverted) + x,
//								                                  Mathf.FloorToInt( cursor.y * Block45Constants._scaleInverted) + y,
//								                                  Mathf.FloorToInt( cursor.z * Block45Constants._scaleInverted) + z);
//								Block45Man.self.DataSource.Write(block, inpos.x,
//								                                 inpos.y,
//								                                 inpos.z);
//							}
//						}
//					}
//
//				}
//			}
        }
    }
Ejemplo n.º 20
0
        public void CameraMoveTo(IntVector3 p)
        {
            var eye = GetEyeFromLookTarget(p);
            var target = p.ToVector3();

            this.CameraMoveService.Move(eye, target);
        }
Ejemplo n.º 21
0
    void Update()
    {
        if (VCEditor.SelectedPart == null)
        {
            return;
        }
        if (VCEInput.s_Cancel)
        {
            Cancel();
            return;
        }

        if (VCEditor.SelectedPart != m_LastSelectedPart)
        {
            if (m_PartInst != null)
            {
                GameObject.Destroy(m_PartInst);
            }
            if (VCEditor.SelectedPart.m_ResObj == null)
            {
                Debug.LogError("This part has no prefab resource: " + VCEditor.SelectedPart.m_Name);
                Cancel();
                return;
            }
            m_PartInst = GameObject.Instantiate(VCEditor.SelectedPart.m_ResObj) as GameObject;
            m_PartInst.SetActive(false);
            m_PartInst.transform.parent        = this.transform;
            m_PartInst.transform.localPosition = Vector3.zero;
            m_Tool            = m_PartInst.GetComponent <VCEComponentTool>();
            m_Tool.m_IsBrush  = true;
            m_Tool.m_InEditor = true;
            m_Tool.m_ToolGroup.SetActive(true);

            Collider[] cs = m_PartInst.GetComponentsInChildren <Collider>(true);
            foreach (Collider c in cs)
            {
                if (c.gameObject != m_Tool.m_ToolGroup.gameObject)
                {
                    Collider.Destroy(c);
                }
                else
                {
                    c.enabled = false;
                }
            }

            m_LastSelectedPart = VCEditor.SelectedPart;
        }

        float voxel_size = VCEditor.s_Scene.m_Setting.m_VoxelSize;

        if (!VCEInput.s_MouseOnUI && VCEMath.RayCastDrawTarget(VCEInput.s_PickRay, out m_Target, VCEMath.MC_ISO_VALUE) && VCEditor.s_Scene.m_IsoData.IsPointIn(m_Target.cursor))
        {
            m_PartInst.SetActive(true);
            Vector3    point  = m_Target.rch.point * 2;
            IntVector3 ipoint = new IntVector3(point);
            m_Tool.SetPivotPos(ipoint.ToVector3() * 0.5f * voxel_size);

            bool canput = true;
            if (VCEditor.s_Scene.m_IsoData.FindComponentsAtPos(m_PartInst.transform.localPosition).Count > 0)
            {
                canput = false;
            }
            // Mirror
            if (VCEditor.s_Mirror.Enabled_Masked)
            {
                VCEditor.s_Mirror.CalcPrepare(VCEditor.s_Scene.m_Setting.m_VoxelSize);
                if (m_PartInst.transform.localPosition.x == VCEditor.s_Mirror.WorldPos.x && VCEditor.s_Mirror.XPlane_Masked)
                {
                    canput = false;
                }
                if (m_PartInst.transform.localPosition.y == VCEditor.s_Mirror.WorldPos.y && VCEditor.s_Mirror.YPlane_Masked)
                {
                    canput = false;
                }
                if (m_PartInst.transform.localPosition.z == VCEditor.s_Mirror.WorldPos.z && VCEditor.s_Mirror.ZPlane_Masked)
                {
                    canput = false;
                }
            }
            if (canput)
            {
                m_Tool.m_SelBound.m_BoundColor = GLComponentBound.s_Green;
                m_Tool.m_SelBound.m_Highlight  = false;
            }
            else
            {
                m_Tool.m_SelBound.m_BoundColor = GLComponentBound.s_Red;
                m_Tool.m_SelBound.m_Highlight  = true;
            }

            if (Input.GetMouseButtonDown(0) && canput)
            {
                Do();
            }
        }
        else
        {
            m_PartInst.SetActive(false);
        }
    }
Ejemplo n.º 22
0
        bool ResolvePaintPosition(ref Ray ray, ref IntVector3 brushPosition)
        {
            var brushPositionWorld = brushPosition.ToVector3();

            Matrix world;
            Matrix.CreateTranslation(ref brushPositionWorld, out world);

            var rayDirection = ray.Direction;
            rayDirection.Normalize();

            for (int i = 0; i < triangleInfos.Length; i++)
            {
                var side = triangleInfos[i].Side;

                // 面固定済みならば、それ以外の面を除外。
                if (PaintStarted && lockedSide != null && side != lockedSide)
                    continue;

                // 背面は判定から除外。
                if (IsBackFace(side, ref rayDirection)) continue;

                // 面と視線が交差するか否か。
                if (Intersects(ref ray, triangleInfos[i], ref world))
                {
                    var testPosition = brushPosition + side.Direction;
                    var blockIndex = Manager.GetBlockIndex(ref testPosition);
                    if (blockIndex == Block.EmptyIndex)
                    {
                        PaintPosition = testPosition;
                        paintSide = side;
                        return true;
                    }
                }
            }

            return false;
        }
Ejemplo n.º 23
0
    public static bool RayCastDrawTarget(Ray ray, IBSDataSource ds, out DrawTarget target, int minvol, bool ignoreDiagonal = true, params IBSDataSource[] relative_ds)
    {
        target = new DrawTarget();

        RaycastHit rch;
        float      dis = Upsilon;

//		bool cast = false;

        if (ds == null)
        {
            return(false);
        }

        IBSDataSource fds = null;

        if (RayCastV(ray, ds, out rch, minvol))
        {
            dis = rch.distance;
//			cast = true;
            fds = ds;
        }


        foreach (IBSDataSource _ds in relative_ds)
        {
            RaycastHit _rch;
            if (_ds != ds && RayCastV(ray, _ds, out _rch, minvol))
            {
                if (dis > _rch.distance)
                {
                    rch = _rch;
                    dis = _rch.distance;
                    fds = _ds;
                }
            }
        }

        target.ds = fds;
        if (fds != null)
        {
            if (fds == ds)
            {
                target.rch    = rch;
                target.snapto = new Vector3(Mathf.FloorToInt((rch.point.x - rch.normal.x * 0.5f) * ds.ScaleInverted) * ds.Scale,
                                            Mathf.FloorToInt((rch.point.y - rch.normal.y * 0.5f) * ds.ScaleInverted) * ds.Scale,
                                            Mathf.FloorToInt((rch.point.z - rch.normal.z * 0.5f) * ds.ScaleInverted) * ds.Scale);
                target.cursor = new Vector3(Mathf.FloorToInt((rch.point.x + rch.normal.x * 0.5f) * ds.ScaleInverted) * ds.Scale,
                                            Mathf.FloorToInt((rch.point.y + rch.normal.y * 0.5f) * ds.ScaleInverted) * ds.Scale,
                                            Mathf.FloorToInt((rch.point.z + rch.normal.z * 0.5f) * ds.ScaleInverted) * ds.Scale);


                IntVector3 offset = DiagonalOffset(rch.point * ds.ScaleInverted, rch.normal * ds.ScaleInverted, ds.DiagonalOffset);

                if (offset.x != 0)
                {
                    Vector3 _snap = target.snapto * ds.ScaleInverted + new Vector3(offset.x, 0, 0);
                    BSVoxel voxel = ds.SafeRead((int)_snap.x, (int)_snap.y, (int)_snap.z);
                    if (!ds.VoxelIsZero(voxel, minvol))
                    {
                        offset.x = 0;
                    }
                }


                if (offset.y != 0)
                {
                    Vector3 _snap = target.snapto * ds.ScaleInverted + new Vector3(0, offset.y, 0);
                    BSVoxel voxel = ds.SafeRead((int)_snap.x, (int)_snap.y, (int)_snap.z);
                    if (!ds.VoxelIsZero(voxel, minvol))
                    {
                        offset.y = 0;
                    }
                }


                if (offset.z != 0)
                {
                    Vector3 _snap = target.snapto * ds.ScaleInverted + new Vector3(0, 0, offset.z);
                    BSVoxel voxel = ds.SafeRead((int)_snap.x, (int)_snap.y, (int)_snap.z);
                    if (!ds.VoxelIsZero(voxel, minvol))
                    {
                        offset.z = 0;
                    }
                }

                if (offset.x != 0 && offset.y != 0)
                {
                    Vector3 _snap = target.snapto * ds.ScaleInverted + new Vector3(offset.x, offset.y, 0);
                    BSVoxel voxel = ds.SafeRead((int)_snap.x, (int)_snap.y, (int)_snap.z);
                    if (!ds.VoxelIsZero(voxel, minvol))
                    {
                        offset.x = 0;
                        offset.y = 0;
                    }
                }

                if (offset.x != 0 && offset.z != 0)
                {
                    Vector3 _snap = target.snapto * ds.ScaleInverted + new Vector3(offset.x, 0, offset.z);
                    BSVoxel voxel = ds.SafeRead((int)_snap.x, (int)_snap.y, (int)_snap.z);
                    if (!ds.VoxelIsZero(voxel, minvol))
                    {
                        offset.x = 0;
                        offset.z = 0;
                    }
                }

                if (offset.y != 0 && offset.z != 0)
                {
                    Vector3 _snap = target.snapto * ds.ScaleInverted + new Vector3(0, offset.y, offset.z);
                    BSVoxel voxel = ds.SafeRead((int)_snap.x, (int)_snap.y, (int)_snap.z);
                    if (!ds.VoxelIsZero(voxel, minvol))
                    {
                        offset.y = 0;
                        offset.z = 0;
                    }
                }

                target.cursor = target.cursor + (offset.ToVector3()) * ds.Scale;

                if (ds == BuildingMan.Blocks)
                {
                    if (!ignoreDiagonal)
                    {
                        Vector3 _snap = target.snapto * ds.ScaleInverted;
                        BSVoxel voxel = ds.SafeRead((int)_snap.x, (int)_snap.y, (int)_snap.z);
                        if (voxel.blockType > 128)
                        {
                            if (voxel.blockType >> 2 != 63)
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
            else
            {
                rch.point += fds.Offset;
                rch.point -= ds.Offset;

                target.rch = rch;
                float factor = Mathf.Min(fds.Scale, ds.Scale);
                target.snapto = new Vector3(Mathf.FloorToInt((rch.point.x - rch.normal.x * 0.5f * factor) * ds.ScaleInverted) * ds.Scale,
                                            Mathf.FloorToInt((rch.point.y - rch.normal.y * 0.5f * factor) * ds.ScaleInverted) * ds.Scale,
                                            Mathf.FloorToInt((rch.point.z - rch.normal.z * 0.5f * factor) * ds.ScaleInverted) * ds.Scale);
                target.cursor = new Vector3(Mathf.FloorToInt((rch.point.x + rch.normal.x * 0.5f * factor) * ds.ScaleInverted) * ds.Scale,
                                            Mathf.FloorToInt((rch.point.y + rch.normal.y * 0.5f * factor) * ds.ScaleInverted) * ds.Scale,
                                            Mathf.FloorToInt((rch.point.z + rch.normal.z * 0.5f * factor) * ds.ScaleInverted) * ds.Scale);
            }

            return(true);
        }

        return(false);
    }
Ejemplo n.º 24
0
    protected override void Do()
    {
        m_Action = new VCEAction();

        ulong oldmat_guid = VCEditor.s_Scene.m_IsoData.MaterialGUID(VCEditor.SelectedVoxelType);
        ulong newmat_guid = VCEditor.SelectedMaterial.m_Guid;

        if (oldmat_guid != newmat_guid)
        {
            VCEAlterMaterialMap modify = new VCEAlterMaterialMap(VCEditor.SelectedVoxelType, oldmat_guid, newmat_guid);
            m_Action.Modifies.Add(modify);
        }

        float maskx    = (m_Direction == ECoordAxis.X) ? 0.0f : 1.0f;
        float masky    = (m_Direction == ECoordAxis.Y) ? 0.0f : 1.0f;
        float maskz    = (m_Direction == ECoordAxis.Z) ? 0.0f : 1.0f;
        int   imaskx   = (m_Direction == ECoordAxis.X) ? 0 : 1;
        int   imasky   = (m_Direction == ECoordAxis.Y) ? 0 : 1;
        int   imaskz   = (m_Direction == ECoordAxis.Z) ? 0 : 1;
        float invmaskx = (m_Direction == ECoordAxis.X) ? 1000000.0f : 1.0f;
        float invmasky = (m_Direction == ECoordAxis.Y) ? 1000000.0f : 1.0f;
        float invmaskz = (m_Direction == ECoordAxis.Z) ? 1000000.0f : 1.0f;

        VCEditor.s_Mirror.CalcPrepare(VCEditor.s_Scene.m_Setting.m_VoxelSize);
        IntVector3 min           = Min;
        IntVector3 max           = Max;
        Vector3    extend        = Size.ToVector3() * 0.5f;
        Vector3    center        = min.ToVector3() + extend;
        Vector3    inv_scale     = Vector3.one;
        float      radius        = Mathf.Max(extend.x * maskx, extend.y * masky, extend.z * maskz);
        float      min_dimension = Mathf.Max(Mathf.Min(extend.x * invmaskx, extend.y * invmasky, extend.z * invmaskz) - 0.5f, 1);

        if (extend.x * maskx >= extend.y * masky && extend.x * maskx >= extend.z * maskz)
        {
            inv_scale = new Vector3(1, extend.x / extend.y, extend.x / extend.z);
        }
        else if (extend.y * masky >= extend.x * maskx && extend.y * masky >= extend.z * maskz)
        {
            inv_scale = new Vector3(extend.y / extend.x, 1, extend.y / extend.z);
        }
        else
        {
            inv_scale = new Vector3(extend.z / extend.x, extend.z / extend.y, 1);
        }

        float sizex = max.x - min.x + 0.5f;
        float sizey = max.y - min.y + 0.5f;
        float sizez = max.z - min.z + 0.5f;

        for (int x = min.x - 2 * imaskx; x <= max.x + 2 * imaskx; ++x)
        {
            for (int y = min.y - 2 * imasky; y <= max.y + 2 * imasky; ++y)
            {
                for (int z = min.z - 2 * imaskz; z <= max.z + 2 * imaskz; ++z)
                {
                    float lerpt = 1;
                    if (m_Direction == ECoordAxis.X)
                    {
                        lerpt = (float)(x - min.x) / sizex;
                    }
                    else if (m_Direction == ECoordAxis.Y)
                    {
                        lerpt = (float)(y - min.y) / sizey;
                    }
                    else if (m_Direction == ECoordAxis.Z)
                    {
                        lerpt = (float)(z - min.z) / sizez;
                    }
                    float scl = Mathf.Lerp(m_NegativeScale, m_PositiveScale, lerpt);
                    if (scl * radius < 0.01f)
                    {
                        scl = 0.01f / radius;
                    }

                    IntVector3 pos = new IntVector3(x, y, z);
                    // Mirror
                    if (VCEditor.s_Mirror.Enabled_Masked)
                    {
                        Vector3 sphere_coord = (pos.ToVector3() + Vector3.one * 0.5f) - center;
                        sphere_coord.x *= inv_scale.x;
                        sphere_coord.y *= inv_scale.y;
                        sphere_coord.z *= inv_scale.z;
                        sphere_coord.x *= maskx;
                        sphere_coord.y *= masky;
                        sphere_coord.z *= maskz;

                        float _radius = scl * radius;
                        float delta   = (_radius - sphere_coord.magnitude) / _radius;
                        float volume  = Mathf.Clamp(delta * min_dimension * scl * VCEMath.MC_ISO_VALUEF + VCEMath.MC_ISO_VALUEF, 0, 255.49f);

                        VCEditor.s_Mirror.MirrorVoxel(pos);

                        for (int i = 0; i < VCEditor.s_Mirror.OutputCnt; ++i)
                        {
                            pos = VCEditor.s_Mirror.Output[i];
                            if (VCEditor.s_Scene.m_IsoData.IsPointIn(pos))
                            {
                                int     voxel_pos = VCIsoData.IPosToKey(pos);
                                VCVoxel old_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(voxel_pos);
                                VCVoxel new_voxel = 0;
                                if (old_voxel.Volume == 0)
                                {
                                    new_voxel = new VCVoxel((byte)(volume), (byte)VCEditor.SelectedVoxelType);
                                }
                                else if (old_voxel.Volume < VCEMath.MC_ISO_VALUE)
                                {
                                    if (volume < VCEMath.MC_ISO_VALUE)
                                    {
                                        new_voxel = old_voxel;
                                    }
                                    else
                                    {
                                        new_voxel = new VCVoxel((byte)(volume), (byte)VCEditor.SelectedVoxelType);
                                    }
                                }
                                else
                                {
                                    if (volume < VCEMath.MC_ISO_VALUE)
                                    {
                                        new_voxel = old_voxel;
                                    }
                                    else
                                    {
                                        new_voxel = new VCVoxel((byte)(volume), (byte)VCEditor.SelectedVoxelType);
                                    }
                                }
                                VCVoxel old_st_voxel = VCEditor.s_Scene.m_Stencil.GetVoxel(voxel_pos);
                                new_voxel.Volume = (new_voxel.Volume > old_st_voxel.Volume) ? (new_voxel.Volume) : (old_st_voxel.Volume);
                                VCEditor.s_Scene.m_Stencil.SetVoxel(voxel_pos, new_voxel);
                            }
                        }
                    }
                    // No mirror
                    else
                    {
                        if (VCEditor.s_Scene.m_IsoData.IsPointIn(pos))
                        {
                            Vector3 sphere_coord = (pos.ToVector3() + Vector3.one * 0.5f) - center;
                            sphere_coord.x *= inv_scale.x;
                            sphere_coord.y *= inv_scale.y;
                            sphere_coord.z *= inv_scale.z;
                            sphere_coord.x *= maskx;
                            sphere_coord.y *= masky;
                            sphere_coord.z *= maskz;

                            float _radius = scl * radius;
                            float delta   = (_radius - sphere_coord.magnitude) / _radius;
                            float volume  = Mathf.Clamp(delta * min_dimension * scl * VCEMath.MC_ISO_VALUEF + VCEMath.MC_ISO_VALUEF, 0, 255.49f);

                            int     voxel_pos = VCIsoData.IPosToKey(pos);
                            VCVoxel old_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(voxel_pos);
                            VCVoxel new_voxel = 0;
                            if (old_voxel.Volume == 0)
                            {
                                new_voxel = new VCVoxel((byte)(volume), (byte)VCEditor.SelectedVoxelType);
                            }
                            else if (old_voxel.Volume < VCEMath.MC_ISO_VALUE)
                            {
                                if (volume < VCEMath.MC_ISO_VALUE)
                                {
                                    new_voxel = old_voxel;
                                }
                                else
                                {
                                    new_voxel = new VCVoxel((byte)(volume), (byte)VCEditor.SelectedVoxelType);
                                }
                            }
                            else
                            {
                                if (volume < VCEMath.MC_ISO_VALUE)
                                {
                                    new_voxel = old_voxel;
                                }
                                else
                                {
                                    new_voxel = new VCVoxel((byte)(volume), (byte)VCEditor.SelectedVoxelType);
                                }
                            }
                            VCEditor.s_Scene.m_Stencil.SetVoxel(voxel_pos, new_voxel);
                        }
                    }
                }
            }
        }
        VCEditor.s_Scene.m_Stencil.NormalizeAllVoxels();
        foreach (KeyValuePair <int, VCVoxel> kvp in VCEditor.s_Scene.m_Stencil.m_Voxels)
        {
            VCVoxel old_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(kvp.Key);
            VCVoxel new_voxel = VCEditor.s_Scene.m_Stencil.GetVoxel(kvp.Key);
            if (old_voxel != new_voxel)
            {
                VCEAlterVoxel modify = new VCEAlterVoxel(kvp.Key, old_voxel, new_voxel);
                m_Action.Modifies.Add(modify);
            }
        }
        VCEditor.s_Scene.m_Stencil.Clear();
        if (m_Action.Modifies.Count > 0)
        {
            m_Action.Do();
        }
        ResetDrawing();
    }
Ejemplo n.º 25
0
    void Update()
    {
        if (VCEditor.SelectedDecalGUID == 0)
        {
            return;
        }
        if (VCEditor.SelectedDecalIndex < 0)
        {
            return;
        }
        if (VCEditor.SelectedDecal == null)
        {
            return;
        }
        if (VCEInput.s_Cancel)
        {
            Cancel();
            return;
        }
        m_DecalInst.m_Guid = VCEditor.SelectedDecalGUID;

        float      voxel_size = VCEditor.s_Scene.m_Setting.m_VoxelSize;
        RaycastHit rch;

        if (!VCEInput.s_MouseOnUI && VCEMath.RayCastVoxel(VCEInput.s_PickRay, out rch, VCEMath.MC_ISO_VALUE))
        {
            AdjustBrush();
            m_DecalInst.gameObject.SetActive(true);
            Vector3    point  = rch.point * 2;
            IntVector3 ipoint = new IntVector3(point);
            m_Tool.SetPivotPos(ipoint.ToVector3() * 0.5f * voxel_size);
            m_DecalInst.transform.localRotation = Quaternion.LookRotation(-rch.normal);
            m_DecalInst.transform.Rotate(-rch.normal, m_RotateAngle, Space.World);

            bool canput = true;
            List <VCComponentData> poscdatas = VCEditor.s_Scene.m_IsoData.FindComponentsAtPos(m_DecalInst.transform.localPosition, VCDecalData.s_ComponentId);
            foreach (VCComponentData cd in poscdatas)
            {
                VCDecalData ddata = cd as VCDecalData;
                if (ddata != null)
                {
                    if (ddata.m_Guid == m_DecalInst.m_Guid)
                    {
                        canput = false;
                        break;
                    }
                }
            }

            // Mirror
            if (VCEditor.s_Mirror.Enabled_Masked)
            {
                VCEditor.s_Mirror.CalcPrepare(VCEditor.s_Scene.m_Setting.m_VoxelSize);
                if (m_DecalInst.transform.localPosition.x == VCEditor.s_Mirror.WorldPos.x && VCEditor.s_Mirror.XPlane_Masked)
                {
                    canput = false;
                }
                if (m_DecalInst.transform.localPosition.y == VCEditor.s_Mirror.WorldPos.y && VCEditor.s_Mirror.YPlane_Masked)
                {
                    canput = false;
                }
                if (m_DecalInst.transform.localPosition.z == VCEditor.s_Mirror.WorldPos.z && VCEditor.s_Mirror.ZPlane_Masked)
                {
                    canput = false;
                }
            }
            if (canput)
            {
                m_Tool.m_SelBound.m_BoundColor = GLComponentBound.s_Green;
                m_Tool.m_SelBound.m_Highlight  = false;
            }
            else
            {
                m_Tool.m_SelBound.m_BoundColor = GLComponentBound.s_Red;
                m_Tool.m_SelBound.m_Highlight  = true;
            }

            if (Input.GetMouseButtonDown(0) && canput)
            {
                Do();
            }
        }
        else
        {
            m_DecalInst.gameObject.SetActive(false);
        }
    }
Ejemplo n.º 26
0
        static void HandleTree(VertexList<SceneryVertex> sceneryVertexList, TileData td, ref IntVector3 pos)
        {
            SymbolID symbol;
            Color color;

            switch (td.ID)
            {
                case TileID.Tree:
                    switch (td.MaterialID)
                    {
                        case MaterialID.Fir:
                            symbol = SymbolID.ConiferousTree;
                            break;

                        case MaterialID.Pine:
                            symbol = SymbolID.ConiferousTree2;
                            break;

                        case MaterialID.Birch:
                            symbol = SymbolID.DeciduousTree;
                            break;

                        case MaterialID.Oak:
                            symbol = SymbolID.DeciduousTree2;
                            break;

                        default:
                            throw new Exception();
                    }
                    break;

                case TileID.Sapling:
                    switch (td.MaterialID)
                    {
                        case MaterialID.Fir:
                            symbol = SymbolID.ConiferousSapling;
                            break;

                        case MaterialID.Pine:
                            symbol = SymbolID.ConiferousSapling2;
                            break;

                        case MaterialID.Birch:
                            symbol = SymbolID.DeciduousSapling;
                            break;

                        case MaterialID.Oak:
                            symbol = SymbolID.DeciduousSapling2;
                            break;

                        default:
                            throw new Exception();
                    }
                    break;

                case TileID.DeadTree:
                    symbol = SymbolID.DeadTree;
                    break;

                default:
                    throw new Exception();
            }

            color = Color.ForestGreen;

            sceneryVertexList.Add(new SceneryVertex(pos.ToVector3(), Color.LightGreen, (uint)symbol));
        }
Ejemplo n.º 27
0
 // Indexed-position to world position
 public static Vector3 PosToWorldPos(IntVector3 ipos)
 {
     return(ipos.ToVector3() * LSubTerrConstant.SizeF);
 }
Ejemplo n.º 28
0
 public void SetPerObjectConstBuf(IntVector3 offset)
 {
     m_objectWorldMatrixParam.SetValue(offset.ToVector3());
     m_perObConstBuf.Update();
 }
Ejemplo n.º 29
0
    // Update is called once per frame
    void Update()
    {
        m_GizmoMesh.Clear();
        Vector3[] verts   = new Vector3 [36];
        Vector3[] norms   = new Vector3 [36];
        Vector2[] uvs     = new Vector2 [36];
        int[]     indices = new int [36];

        Vector3 size = m_VoxelSize * m_CubeSize.ToVector3();
        Vector3 min  = new Vector3(m_VoxelSize * m_Shrink, m_VoxelSize * m_Shrink, m_VoxelSize * m_Shrink);
        Vector3 max  = size - min;

        verts[2] = new Vector3(min.x, min.y, min.z);
        verts[1] = new Vector3(min.x, max.y, min.z);
        verts[0] = new Vector3(min.x, max.y, max.z);
        verts[5] = new Vector3(min.x, max.y, max.z);
        verts[4] = new Vector3(min.x, min.y, max.z);
        verts[3] = new Vector3(min.x, min.y, min.z);

        verts[6]  = new Vector3(max.x, min.y, min.z);
        verts[7]  = new Vector3(max.x, max.y, min.z);
        verts[8]  = new Vector3(max.x, max.y, max.z);
        verts[9]  = new Vector3(max.x, max.y, max.z);
        verts[10] = new Vector3(max.x, min.y, max.z);
        verts[11] = new Vector3(max.x, min.y, min.z);

        verts[12 + 0] = new Vector3(min.x, min.y, min.z);
        verts[12 + 1] = new Vector3(max.x, min.y, min.z);
        verts[12 + 2] = new Vector3(max.x, min.y, max.z);
        verts[12 + 3] = new Vector3(max.x, min.y, max.z);
        verts[12 + 4] = new Vector3(min.x, min.y, max.z);
        verts[12 + 5] = new Vector3(min.x, min.y, min.z);

        verts[12 + 8]  = new Vector3(min.x, max.y, min.z);
        verts[12 + 7]  = new Vector3(max.x, max.y, min.z);
        verts[12 + 6]  = new Vector3(max.x, max.y, max.z);
        verts[12 + 11] = new Vector3(max.x, max.y, max.z);
        verts[12 + 10] = new Vector3(min.x, max.y, max.z);
        verts[12 + 9]  = new Vector3(min.x, max.y, min.z);

        verts[24 + 0] = new Vector3(min.x, min.y, min.z);
        verts[24 + 1] = new Vector3(min.x, max.y, min.z);
        verts[24 + 2] = new Vector3(max.x, max.y, min.z);
        verts[24 + 3] = new Vector3(max.x, max.y, min.z);
        verts[24 + 4] = new Vector3(max.x, min.y, min.z);
        verts[24 + 5] = new Vector3(min.x, min.y, min.z);

        verts[24 + 8]  = new Vector3(min.x, min.y, max.z);
        verts[24 + 7]  = new Vector3(min.x, max.y, max.z);
        verts[24 + 6]  = new Vector3(max.x, max.y, max.z);
        verts[24 + 11] = new Vector3(max.x, max.y, max.z);
        verts[24 + 10] = new Vector3(max.x, min.y, max.z);
        verts[24 + 9]  = new Vector3(min.x, min.y, max.z);

        norms[0] = Vector3.left;
        norms[1] = Vector3.left;
        norms[2] = Vector3.left;
        norms[3] = Vector3.left;
        norms[4] = Vector3.left;
        norms[5] = Vector3.left;

        norms[6 + 0] = Vector3.right;
        norms[6 + 1] = Vector3.right;
        norms[6 + 2] = Vector3.right;
        norms[6 + 3] = Vector3.right;
        norms[6 + 4] = Vector3.right;
        norms[6 + 5] = Vector3.right;

        norms[12 + 0] = Vector3.down;
        norms[12 + 1] = Vector3.down;
        norms[12 + 2] = Vector3.down;
        norms[12 + 3] = Vector3.down;
        norms[12 + 4] = Vector3.down;
        norms[12 + 5] = Vector3.down;

        norms[18 + 0] = Vector3.up;
        norms[18 + 1] = Vector3.up;
        norms[18 + 2] = Vector3.up;
        norms[18 + 3] = Vector3.up;
        norms[18 + 4] = Vector3.up;
        norms[18 + 5] = Vector3.up;

        norms[24 + 0] = Vector3.back;
        norms[24 + 1] = Vector3.back;
        norms[24 + 2] = Vector3.back;
        norms[24 + 3] = Vector3.back;
        norms[24 + 4] = Vector3.back;
        norms[24 + 5] = Vector3.back;

        norms[30 + 0] = Vector3.forward;
        norms[30 + 1] = Vector3.forward;
        norms[30 + 2] = Vector3.forward;
        norms[30 + 3] = Vector3.forward;
        norms[30 + 4] = Vector3.forward;
        norms[30 + 5] = Vector3.forward;

        for (int f = 0; f < 6; ++f)
        {
            float w = 1, h = 1;
            switch (f)
            {
            case 0: h = m_CubeSize.y; w = m_CubeSize.z; break;

            case 1: w = m_CubeSize.y; h = m_CubeSize.z; break;

            case 2: w = m_CubeSize.x; h = m_CubeSize.z; break;

            case 3: h = m_CubeSize.x; w = m_CubeSize.z; break;

            case 4: w = m_CubeSize.y; h = m_CubeSize.x; break;

            case 5: h = m_CubeSize.y; w = m_CubeSize.x; break;
            }
            uvs[f * 6 + 0] = new Vector2(0, 0);
            uvs[f * 6 + 1] = new Vector2(w, 0);
            uvs[f * 6 + 2] = new Vector2(w, h);
            uvs[f * 6 + 3] = new Vector2(w, h);
            uvs[f * 6 + 4] = new Vector2(0, h);
            uvs[f * 6 + 5] = new Vector2(0, 0);
            for (int i = 0; i < 6; ++i)
            {
                int index = f * 6 + i;
                indices[index] = index;
            }
        }
        m_GizmoMesh.vertices = verts;
        m_GizmoMesh.normals  = norms;
        m_GizmoMesh.uv       = uvs;
        m_GizmoMesh.SetTriangles(indices, 0);

        if (m_ShapeGizmo != null)
        {
            m_ShapeGizmo.transform.localScale    = m_CubeSize.ToVector3() * m_VoxelSize;
            m_ShapeGizmo.transform.localPosition = m_CubeSize.ToVector3() * m_VoxelSize * 0.5f;
            m_ShapeGizmo.GetComponentsInChildren <Renderer>(true)[0].material.renderQueue = 3000;
        }
    }
Ejemplo n.º 30
0
 public void SetPerObjectConstBuf(IntVector3 offset)
 {
     m_objectWorldMatrixParam.SetValue(offset.ToVector3());
     m_perObConstBuf.Update();
 }
Ejemplo n.º 31
0
    // Update is called once per frame
    void Update()
    {
        if (!VCEditor.DocumentOpen() ||
            VCEditor.SelectedVoxelType < 0 ||
            VCEInput.s_MouseOnUI)
        {
            m_GizmoGroup.gameObject.SetActive(false);
            return;
        }
        // Cancel
        if (VCEInput.s_Cancel)
        {
            Cancel();
        }
        if (VCEInput.s_Shift && VCEInput.s_Left)
        {
            m_Offset = m_Offset - IntVector3.UnitX;
        }
        if (VCEInput.s_Shift && VCEInput.s_Right)
        {
            m_Offset = m_Offset + IntVector3.UnitX;
        }
        if (VCEInput.s_Shift && VCEInput.s_Up)
        {
            m_Offset = m_Offset + IntVector3.UnitY;
        }
        if (VCEInput.s_Shift && VCEInput.s_Down)
        {
            m_Offset = m_Offset - IntVector3.UnitY;
        }
        if (VCEInput.s_Shift && VCEInput.s_Forward)
        {
            m_Offset = m_Offset + IntVector3.UnitZ;
        }
        if (VCEInput.s_Shift && VCEInput.s_Back)
        {
            m_Offset = m_Offset - IntVector3.UnitZ;
        }

        float voxel_size = VCEditor.s_Scene.m_Setting.m_VoxelSize;

        m_CursorGizmoCube.m_VoxelSize = voxel_size;
        m_OffsetGizmoCube.m_VoxelSize = voxel_size;

        if (VCEMath.RayCastDrawTarget(VCEInput.s_PickRay, out m_Target, VCEMath.MC_ISO_VALUE))
        {
            m_GizmoGroup.gameObject.SetActive(true);
            IntVector3 draw = m_Target.cursor + m_Offset;
            m_CursorGizmoCube.transform.position = m_Target.cursor.ToVector3() * voxel_size;
            m_OffsetGizmoCube.transform.position = draw.ToVector3() * voxel_size;
            bool cursor_in   = VCEditor.s_Scene.m_IsoData.IsPointIn(m_Target.cursor);
            bool offset_in   = VCEditor.s_Scene.m_IsoData.IsPointIn(draw);
            bool show_offset = (m_Offset.ToVector3().magnitude > 0.1f);
            m_CursorGizmoCube.gameObject.SetActive(cursor_in && show_offset);
            m_OffsetGizmoCube.gameObject.SetActive(offset_in);
            if (cursor_in && offset_in && Input.GetMouseButtonDown(0))
            {
                Do();
            }
        }
        else
        {
            m_GizmoGroup.gameObject.SetActive(false);
        }
    }
Ejemplo n.º 32
0
    void CheckTerrain()
    {
        Ray        ray = PeCamera.mouseRay;
        RaycastHit hitInfo;

        mOpCube.Enable = false;
        if (Physics.Raycast(ray, out hitInfo, 100f, 1 << Pathea.Layer.VFVoxelTerrain))
        {
            VFVoxelChunkGo chunk = hitInfo.collider.gameObject.GetComponent <VFVoxelChunkGo>();
            if (chunk != null)
            {
                mOpCube.Enable = true;
                IntVector3 basePos = new IntVector3();

                if (hitInfo.normal.x == 0 || hitInfo.point.x - (int)hitInfo.point.x > 0.5f)
                {
                    basePos.x = Mathf.RoundToInt(hitInfo.point.x);
                }
                else
                {
                    basePos.x = hitInfo.normal.x > 0 ? Mathf.CeilToInt(hitInfo.point.x) : Mathf.FloorToInt(hitInfo.point.x);
                }

                if (hitInfo.normal.y == 0 || hitInfo.point.y - (int)hitInfo.point.y > 0.5f)
                {
                    basePos.y = Mathf.RoundToInt(hitInfo.point.y);
                }
                else
                {
                    basePos.y = hitInfo.normal.y > 0 ? Mathf.CeilToInt(hitInfo.point.y) : Mathf.FloorToInt(hitInfo.point.y);
                }

                if (hitInfo.normal.z == 0 || hitInfo.point.z - (int)hitInfo.point.z > 0.5f)
                {
                    basePos.z = Mathf.RoundToInt(hitInfo.point.z);
                }
                else
                {
                    basePos.z = hitInfo.normal.z > 0 ? Mathf.CeilToInt(hitInfo.point.z) : Mathf.FloorToInt(hitInfo.point.z);
                }

                IntVector3 nearestPos = basePos;

                float minDis = 100f;

                VFVoxel voxel = VFVoxelTerrain.self.Voxels.SafeRead(basePos.x, basePos.y, basePos.z);

                if (voxel.Volume < 127)
                {
                    for (int i = -1; i <= 1; i++)
                    {
                        for (int j = -1; j <= 1; j++)
                        {
                            for (int k = -1; k <= 1; k++)
                            {
                                IntVector3 now = new IntVector3(basePos.x + i, basePos.y + j, basePos.z + k);
                                voxel = VFVoxelTerrain.self.Voxels.SafeRead(now.x, now.y, now.z);
                                if (voxel.Volume > 127)
                                {
                                    float nowDis = (now.ToVector3() - hitInfo.point).magnitude;
                                    if (minDis >= nowDis)
                                    {
                                        nearestPos = now;
                                        minDis     = nowDis;
                                    }
                                }
                            }
                        }
                    }
                }

                mOpCube.transform.position = nearestPos.ToVector3();
                voxel = VFVoxelTerrain.self.Voxels.SafeRead(nearestPos.x, nearestPos.y, nearestPos.z);

                mOpCube.Enable = Vector3.Distance(mSkillRunner.transform.position + Vector3.up, hitInfo.point) < 3f &&
                                 voxel.Volume > 0 &&
                                 mSkillRunner.GetComponent <Rigidbody>().velocity.sqrMagnitude < 9;
                if (mOpCube.Enable)
                {
                    mTarget = new VFTerrainTarget(hitInfo.point, nearestPos, ref voxel);
                }
            }
            else
            {
                mOpCube.Enable = false;
            }
        }
    }
Ejemplo n.º 33
0
        public void CameraLookAt(IntVector3 p)
        {
            var eye = GetEyeFromLookTarget(p);
            var target = p.ToVector3();

            this.Camera.LookAt(eye, target, Vector3.UnitZ);
        }
Ejemplo n.º 34
0
        Vector3 GetEyeFromLookTarget(IntVector3 p)
        {
            var v = new Vector3(-1, 8, 32.5f) / 32.5f;

            return(p.ToVector3() + v * (this.ViewGridAdjusterService.Height + 0.5f));
        }
Ejemplo n.º 35
0
    public void GetBuildingInfo(out Vector3 size, out Dictionary <IntVector3, B45Block> blocks, out List <Vector3> npcPosition
                                , out List <CreatItemInfo> itemList, out Dictionary <int, BuildingNpc> npcIdPosRot)
    {
        Bounds bound = new Bounds(Vector3.zero, Vector3.zero);

        blocks      = new Dictionary <IntVector3, B45Block>();
        npcPosition = new List <Vector3>();
        itemList    = new List <CreatItemInfo>();
        npcIdPosRot = new Dictionary <int, BuildingNpc>();

        TextAsset    textFile = Resources.Load(mPath) as TextAsset;
        MemoryStream ms       = new MemoryStream(textFile.bytes);
        BinaryReader _in      = new BinaryReader(ms);

        int readVersion = _in.ReadInt32();

        switch (readVersion)
        {
        case 2:
            int Size = _in.ReadInt32();
            for (int i = 0; i < Size; i++)
            {
                IntVector3 index = new IntVector3(_in.ReadInt32(), _in.ReadInt32(), _in.ReadInt32());
                B45Block   block = new B45Block(_in.ReadByte(), _in.ReadByte());
                if ((block.blockType >> 2) != 0)
                {
                    blocks[index] = block;
                    index         = new IntVector3(index);
                    index.x      += 1;
                    index.z      += 1;
                    bound.Encapsulate(BSBlock45Data.s_Scale * index.ToVector3());
                }
            }
            break;
        }


        _in.Close();
        ms.Close();

        BoundSize = size = bound.size;
        UnityEngine.Object subInfo = Resources.Load(mPath + "SubInfo");
        if (null != subInfo)
        {
            textFile = subInfo as TextAsset;
            ms       = new MemoryStream(textFile.bytes);
            _in      = new BinaryReader(ms);

            int version = _in.ReadInt32();
            int count   = _in.ReadInt32();
            switch (version)
            {
            case 1:
                for (int i = 0; i < count; i++)
                {
                    npcPosition.Add(new Vector3(_in.ReadSingle(), _in.ReadSingle(), _in.ReadSingle()));
                }
                break;

            case 2:
                for (int i = 0; i < count; i++)
                {
                    npcPosition.Add(new Vector3(_in.ReadSingle(), _in.ReadSingle(), _in.ReadSingle()));
                }
                count = _in.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    CreatItemInfo addItem = new CreatItemInfo();
                    addItem.mPos      = new Vector3(_in.ReadSingle(), _in.ReadSingle(), _in.ReadSingle());
                    addItem.mRotation = Quaternion.Euler(new Vector3(_in.ReadSingle(), _in.ReadSingle(), _in.ReadSingle()));
                    addItem.mItemId   = _in.ReadInt32();
                    itemList.Add(addItem);
                }
                break;
            }
            _in.Close();
            ms.Close();
        }

        //npc stand
        if (!mNpcIdPosRotStand.Equals("") && mNpcIdPosRotStand.Length > 1)
        {
            string[] npcs = mNpcIdPosRotStand.Split('_');
            for (int i = 0; i < npcs.Count(); i++)
            {
                string[]    npcIdPosRotStr = npcs[i].Split('~');
                int         id             = Convert.ToInt32(npcIdPosRotStr[0]);
                string[]    posRot         = npcIdPosRotStr[1].Split(';');
                string[]    posStr         = posRot[0].Split(',');
                Vector3     pos            = new Vector3(float.Parse(posStr[0]), float.Parse(posStr[1]), float.Parse(posStr[2]));
                float       rot            = float.Parse(posRot[1]);
                BuildingNpc bdnpc          = new BuildingNpc(id, pos, rot, true);
                npcIdPosRot.Add(id, bdnpc);
            }
        }

        //npc move
        if (!mNpcIdPosRotMove.Equals("") && mNpcIdPosRotMove.Length > 1)
        {
            string[] npcs = mNpcIdPosRotMove.Split('_');
            for (int i = 0; i < npcs.Count(); i++)
            {
                string[]    npcIdPosRotStr = npcs[i].Split('~');
                int         id             = Convert.ToInt32(npcIdPosRotStr[0]);
                string[]    posRot         = npcIdPosRotStr[1].Split(';');
                string[]    posStr         = posRot[0].Split(',');
                Vector3     pos            = new Vector3(float.Parse(posStr[0]), float.Parse(posStr[1]), float.Parse(posStr[2]));
                float       rot            = float.Parse(posRot[1]);
                BuildingNpc bdnpc          = new BuildingNpc(id, pos, rot, false);
                npcIdPosRot.Add(id, bdnpc);
            }
        }
    }
Ejemplo n.º 36
0
 private Vector3 GetCenter(int level, IntVector3 coords)
 {
     return(spaceMin + VectorMult(coords.ToVector3() + new Vector3(0.5f, 0.5f, 0.5f), (spaceMax - spaceMin) / (1 << level)));
 }
Ejemplo n.º 37
0
        Vector3 GetEyeFromLookTarget(IntVector3 p)
        {
            var v = new Vector3(-1, 8, 32.5f) / 32.5f;

            return p.ToVector3() + v * (this.ViewGridAdjusterService.Height + 0.5f);
        }