void Update()
    {
        BSMath.DrawTarget dtar;

        if (ShowBlock)
        {
            if (BSMath.RayCastDrawTarget(Camera.main.ScreenPointToRay(Input.mousePosition), BuildingMan.Voxels, out dtar, minVol, true, BuildingMan.Datas))
            {
                m_Center = dtar.snapto;
            }
            else
            {
                m_Center = InvalidPos;
            }
        }
        else
        {
            if (BSMath.RayCastDrawTarget(Camera.main.ScreenPointToRay(Input.mousePosition), BuildingMan.Voxels, out dtar, minVol))
            {
                m_Center = dtar.snapto;
            }
            else
            {
                m_Center = InvalidPos;
            }
        }
    }
    void GetCenterVoxel()
    {
        for (int vol = minVol; vol < BSMath.MC_ISO_VALUE + volAdder; vol += volAdder)
        {
            if (BSMath.RayCastDrawTarget(PeCamera.mouseRay, BuildingMan.Voxels, out m_DTar, vol))
            {
                m_Center = new IntVector3(m_DTar.snapto);
                if (CheckVoxel(m_Center))
                {
                    m_FindVoxel = true;
                    return;
                }
            }
        }

        //checkOriginNear

        if (CheckVoxel(PeCamera.mouseRay.origin - BuildingMan.Voxels.Offset))
        {
            m_Center      = new IntVector3(PeCamera.mouseRay.origin - BuildingMan.Voxels.Offset);
            m_FindVoxel   = true;
            m_DTar        = new BSMath.DrawTarget();
            m_DTar.snapto = m_Center;
            return;
        }

        m_FindVoxel = false;
        m_Center    = InvalidPos;
    }
Beispiel #3
0
    void Update()
    {
        BSMath.DrawTarget dtar;

        if (BSMath.RayCastDrawTarget(Camera.main.ScreenPointToRay(Input.mousePosition), BuildingMan.Blocks, out dtar, BSMath.MC_ISO_VALUE, true, BuildingMan.Datas))
        {
            m_Center = new Vector3(Mathf.FloorToInt(dtar.snapto.x * Block45Constants._scaleInverted) * Block45Constants._scale,
                                   Mathf.FloorToInt(dtar.snapto.y * Block45Constants._scaleInverted) * Block45Constants._scale,
                                   Mathf.FloorToInt(dtar.snapto.z * Block45Constants._scaleInverted) * Block45Constants._scale);
        }
        else
        {
            m_Center = InvalidPos;
        }
    }
Beispiel #4
0
    void Update()
    {
        if (dataSource == null)
        {
            return;
        }

        if (GameConfig.IsInVCE)
        {
            return;
        }

        if (m_Phase == EPhase.Free)
        {
            if (BSInput.s_MouseOnUI)
            {
                gizmoBox.gameObject.SetActive(false);
                return;
            }

            if (BSInput.s_Cancel)
            {
                ResetDrawing();
            }

            // Ray cast voxel
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            BSMath.DrawTarget blockTgt = new BSMath.DrawTarget();
            BSMath.DrawTarget voxelTgt = new BSMath.DrawTarget();
            bool castBlock             = BSMath.RayCastDrawTarget(ray, dataSource, out blockTgt, minvol, true);
            bool castVoxel             = BSMath.RayCastDrawTarget(ray, dataSource, out voxelTgt, minvol, true, BuildingMan.Voxels);

            if (castBlock || castVoxel)
            {
                if (!gizmoBox.gameObject.activeSelf)
                {
                    gizmoBox.gameObject.SetActive(true);
                }

                Vector3 cursor = m_Target.cursor;
                if (castBlock && castVoxel)
                {
                    if (blockTgt.rch.distance <= voxelTgt.rch.distance)
                    {
                        m_Target = blockTgt;
                        cursor   = CalcSnapto(m_Target, dataSource, pattern);
                        m_Cursor = m_Target.rch.point;
                    }
                    else
                    {
                        m_Target = voxelTgt;
                        cursor   = CalcCursor(m_Target, dataSource, 1);
                        m_Cursor = m_Target.rch.point;
                    }
                }
                else if (castBlock)
                {
                    m_Target = blockTgt;
                    cursor   = CalcSnapto(m_Target, dataSource, pattern);
                    m_Cursor = m_Target.rch.point;
                }
                else if (castVoxel)
                {
                    m_Target = voxelTgt;
                    cursor   = CalcCursor(m_Target, dataSource, 1);
                    m_Cursor = m_Target.rch.point;
                }


                gizmoBox.size     = Vector3.one * dataSource.Scale;
                gizmoBox.position = cursor + dataSource.Offset;

                float   offset = dataSource.Scale;
                Vector3 begin  = cursor;
                Vector3 end    = begin + new Vector3(offset, offset, offset);

                // Click mouse and change phase
                if (Input.GetMouseButtonDown(0))
                {
                    m_Begin   = begin;
                    _beginPos = begin;
                    m_End     = end;

                    m_Phase       = EPhase.DragPlane;
                    _prevMousePos = Input.mousePosition;
                }
            }
            else
            {
                ResetDrawing();
            }
        }
        else if (m_Phase == EPhase.DragPlane)
        {
            if (BSInput.s_Cancel)
            {
                ResetDrawing();
                return;
            }

            RaycastHit rch;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            float position = 0;

            if (DragPlane == ECoordPlane.XY)
            {
                position = m_Cursor.z;
            }
            else if (DragPlane == ECoordPlane.XZ)
            {
                position = m_Cursor.y;
            }
            else if (DragPlane == ECoordPlane.ZY)
            {
                position = m_Cursor.x;
            }

            if (BSMath.RayCastCoordPlane(ray, DragPlane, position, out rch))
            {
                m_PointBeforeAdjustHeight = rch.point;
                if (!Vector3.Equals(_prevMousePos, Input.mousePosition))
                {
                    Vector3 point = rch.point - dataSource.Offset;

                    if (DragPlane == ECoordPlane.XZ)
                    {
                        // x
                        float x = 0;
                        m_Begin.x = CalcValue(point.x, _beginPos.x, out x);

                        // z
                        float z = 0;
                        m_Begin.z = CalcValue(point.z, _beginPos.z, out z);

                        m_End = new Vector3(x, _beginPos.y + (pattern.size) * dataSource.Scale, z);
                        m_End = Clamp(m_Begin, m_End);
                    }
                    else if (DragPlane == ECoordPlane.XY)
                    {
                        // x
                        float x = 0;
                        m_Begin.x = CalcValue(point.x, _beginPos.x, out x);

                        // y
                        float y = 0;
                        m_Begin.y = CalcValue(point.y, _beginPos.y, out y);

                        m_End = new Vector3(x, y, _beginPos.z + (pattern.size) * dataSource.Scale);
                        m_End = Clamp(m_Begin, m_End);
                    }
                    else if (DragPlane == ECoordPlane.ZY)
                    {
                        // y
                        float y = 0;
                        m_Begin.y = CalcValue(point.y, _beginPos.y, out y);

                        // z
                        float z = 0;
                        m_Begin.z = CalcValue(point.z, _beginPos.z, out z);

                        m_End = new Vector3(_beginPos.x + (pattern.size) * dataSource.Scale, y, z);
                        m_End = Clamp(m_Begin, m_End);
                    }

                    gizmoBox.position = Min + dataSource.Offset;

                    gizmoBox.size = Size * dataSource.Scale;
                }


                // Click mouse and change phase
                if (Input.GetMouseButtonUp(0))
                {
                    m_Phase       = EPhase.AdjustHeight;
                    _prevMousePos = new Vector3(-100, -100, -100);
                }
            }
        }
        else if (m_Phase == EPhase.AdjustHeight)
        {
            if (BSInput.s_Cancel)
            {
                ResetDrawing();
                return;
            }

            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (DragPlane == ECoordPlane.XZ)
            {
                float adjustHeight = m_PointBeforeAdjustHeight.y;
                BSMath.RayAdjustHeight(ray, ECoordAxis.Y, m_PointBeforeAdjustHeight, out adjustHeight);

                // y
                float y = 0;
                m_Begin.y = CalcValue(adjustHeight, _beginPos.y, out y);
                m_End.y   = y;
            }
            else if (DragPlane == ECoordPlane.XY)
            {
                float adjustHeight = m_PointBeforeAdjustHeight.z;
                BSMath.RayAdjustHeight(ray, ECoordAxis.Z, m_PointBeforeAdjustHeight, out adjustHeight);


                // z
                float z = 0;
                m_Begin.z = CalcValue(adjustHeight, _beginPos.z, out z);
                m_End.z   = z;
            }
            else if (DragPlane == ECoordPlane.ZY)
            {
                float adjustHeight = m_PointBeforeAdjustHeight.x;
                BSMath.RayAdjustHeight(ray, ECoordAxis.X, m_PointBeforeAdjustHeight, out adjustHeight);

                // x
                float x = 0;
                m_Begin.x = CalcValue(adjustHeight, _beginPos.x, out x);
                m_End.x   = x;
            }

            m_End = Clamp(m_Begin, m_End);

            gizmoBox.position = Min + dataSource.Offset;

            gizmoBox.size = Size * dataSource.Scale;

            if (PeInput.Get(PeInput.LogicFunction.Build))
            {
                Do();
                m_Phase = EPhase.Drawing;
            }
        }
        else if (m_Phase == EPhase.Drawing)
        {
            if (BSInput.s_Cancel)
            {
                ResetDrawing();
                return;
            }

            if (BSInput.s_Delete)
            {
                DeleteVoxels();
            }
        }
    }
Beispiel #5
0
    protected void Update()
    {
        if (dataSource == null)
        {
            return;
        }

        if (BSInput.s_MouseOnUI)
        {
            return;
        }

        if (_datasource == dataSource)
        {
            // Clear and rebuild;
            ClearSelection(null);
            _datasource = dataSource;
        }

        if (seletionBoxeRenderer != null)
        {
            seletionBoxeRenderer.m_Boxes = m_SelectionBoxes;
            seletionBoxeRenderer.scale   = dataSource.Scale;
            seletionBoxeRenderer.offset  = dataSource.Offset;
        }

        if (m_RecalcBoxes)
        {
            CalcBoxes();
            m_RecalcBoxes = false;
        }

        if (GameConfig.IsInVCE)
        {
            return;
        }

        // Depth
        if (!BSInput.s_Shift && Input.GetKeyDown(KeyCode.UpArrow))
        {
            Depth      = ++Depth >= maxDragSize ? maxDragSize : Depth;
            m_GUIAlpha = 5;
        }
        else if (!BSInput.s_Shift && Input.GetKeyDown(KeyCode.DownArrow))
        {
            Depth      = --Depth >= 1 ? Depth : 1;
            m_GUIAlpha = 5;
        }

        m_GUIAlpha = Mathf.Lerp(m_GUIAlpha, 0, 0.05f);



        // Drag Box
        //
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (!m_Selecting)
        {
            // Cancel
            if (BSInput.s_Cancel)
            {
                if (!canDo)
                {
                    return;
                }

                Dictionary <IntVector3, byte> old_seletion = new Dictionary <IntVector3, byte>(m_Selections);
                Cancel();
                Dictionary <IntVector3, byte> new_selection = new Dictionary <IntVector3, byte>(m_Selections);

                // For History
                if (old_seletion.Count != 0)
                {
                    BSSelectedBoxModify modify = new BSSelectedBoxModify(old_seletion, new_selection, this);
                    m_Action.AddModify(modify);

                    DoHistory();
                }

                return;
            }

            if (BSMath.RayCastDrawTarget(ray, dataSource, out m_Target, minvol, true, BuildingMan.Datas))
            {
                m_Drawing = true;

                m_Begin   = m_Target.snapto;
                _beginPos = m_Begin;
                m_End     = m_Begin;

                float vx = Mathf.Abs(m_Target.rch.normal.x);
                float vy = Mathf.Abs(m_Target.rch.normal.y);
                float vz = Mathf.Abs(m_Target.rch.normal.z);

                if (vx > 0.9f * m_Target.ds.Scale)
                {
                    m_Coord    = ECoordPlane.ZY;
                    m_PlanePos = m_Target.rch.point.x;
                }
                else if (vy > 0.9f * m_Target.ds.Scale)
                {
                    m_Coord    = ECoordPlane.XZ;
                    m_PlanePos = m_Target.rch.point.y;
                }
                else if (vz > 0.9f * m_Target.ds.Scale)
                {
                    m_Coord    = ECoordPlane.XY;
                    m_PlanePos = m_Target.rch.point.z;
                }

                if (Input.GetMouseButtonDown(0))
                {
                    if (canDo)
                    {
                        m_Selecting = true;
                    }
                }
            }
            else
            {
                m_Drawing = false;
            }
        }
        // Selecting
        else
        {
            m_Drawing = true;

            // Cancel
            if (BSInput.s_Cancel)
            {
                if (!canDo)
                {
                    return;
                }
                m_Selecting = false;
                m_Begin     = new Vector3(-10000, -10000, -10000);
                m_End       = new Vector3(-10000, -10000, -10000);
                return;
            }

            RaycastHit rch;
            if (BSMath.RayCastCoordPlane(ray, m_Coord, m_PlanePos, out rch))
            {
                Vector3 point = rch.point - dataSource.Offset;
                if (m_Coord == ECoordPlane.XY)
                {
                    // x componet
                    float x = 0;
                    m_Begin.x = CalcValue(point.x, _beginPos.x, out x);

                    // y componet
                    float y = 0;
                    m_Begin.y = CalcValue(point.y, _beginPos.y, out y);

                    m_End.x = x;
                    m_End.y = y;
                    m_End.z = Mathf.FloorToInt(point.z * dataSource.ScaleInverted) * dataSource.Scale;


                    if (m_Target.rch.normal.z > 0)
                    {
                        m_Begin.z = m_PlanePos - Depth * dataSource.Scale;
                    }
                    else
                    {
                        m_Begin.z = m_PlanePos + Depth * dataSource.Scale;
                    }

                    m_End = Clamp(m_Begin, m_End);
                }
                else if (m_Coord == ECoordPlane.XZ)
                {
                    // x componet
                    float x = 0;
                    m_Begin.x = CalcValue(point.x, _beginPos.x, out x);

                    // z componet
                    float z = 0;
                    m_Begin.z = CalcValue(point.z, _beginPos.z, out z);

                    m_End.x = x;
                    m_End.y = Mathf.FloorToInt(point.y * dataSource.ScaleInverted) * dataSource.Scale;
                    m_End.z = z;

                    if (m_Target.rch.normal.y > 0)
                    {
                        m_Begin.y = m_PlanePos - Depth * dataSource.Scale;
                    }
                    else
                    {
                        m_Begin.y = m_PlanePos + Depth * dataSource.Scale;
                    }

                    m_End = Clamp(m_Begin, m_End);
                }
                else if (m_Coord == ECoordPlane.ZY)
                {
                    // y componet
                    float y = 0;
                    m_Begin.y = CalcValue(point.y, _beginPos.y, out y);

                    // z componet
                    float z = 0;
                    m_Begin.z = CalcValue(point.z, _beginPos.z, out z);

                    m_End.x = Mathf.FloorToInt(point.x * dataSource.ScaleInverted) * dataSource.Scale;
                    m_End.y = y;
                    m_End.z = z;

                    if (m_Target.rch.normal.x > 0)
                    {
                        m_Begin.x = m_PlanePos - Depth * dataSource.Scale;
                    }
                    else
                    {
                        m_Begin.x = m_PlanePos + Depth * dataSource.Scale;
                    }

                    m_End = Clamp(m_Begin, m_End);
                }
            }

            // In Valid area ?
            if (m_PrevDS != null && m_PrevDS == dataSource)
            {
                if (m_Selections.Count != 0)
                {
                    BSTools.SelBox box = new BSTools.SelBox();
                    box.m_Box.xMin = (short)Mathf.FloorToInt(Mathf.Min(m_Begin.x, m_End.x) * dataSource.ScaleInverted);
                    box.m_Box.yMin = (short)Mathf.FloorToInt(Mathf.Min(m_Begin.y, m_End.y) * dataSource.ScaleInverted);
                    box.m_Box.zMin = (short)Mathf.FloorToInt(Mathf.Min(m_Begin.z, m_End.z) * dataSource.ScaleInverted);
                    box.m_Box.xMax = (short)Mathf.FloorToInt(Mathf.Max(m_Begin.x, m_End.x) * dataSource.ScaleInverted);
                    box.m_Box.yMax = (short)Mathf.FloorToInt(Mathf.Max(m_Begin.y, m_End.y) * dataSource.ScaleInverted);
                    box.m_Box.zMax = (short)Mathf.FloorToInt(Mathf.Max(m_Begin.z, m_End.z) * dataSource.ScaleInverted);

                    // Add current box to list temporarily
                    m_SelectionBoxes.Add(box);
                    BSTools.IntBox bound = BSTools.SelBox.CalculateBound(m_SelectionBoxes);

                    Vector3 size = new Vector3(bound.xMax - bound.xMin, bound.yMax - bound.yMin, bound.zMax - bound.zMin);

                    if (size.x > maxSelectBoxSize.x || size.y > maxSelectBoxSize.y || size.z > maxSelectBoxSize.z)
                    {
                        m_IsValidBox = false;
                    }
                    else
                    {
                        m_IsValidBox = true;
                    }

                    // revert the list
                    m_SelectionBoxes.RemoveAt(m_SelectionBoxes.Count - 1);
                }
                else
                {
                    m_IsValidBox = true;
                }
            }
            else
            {
                m_IsValidBox = true;
            }

            if (Input.GetMouseButtonUp(0))
            {
                if (!canDo)
                {
                    return;
                }

//				bool result = false;

                if (m_IsValidBox)
                {
                    // Add
                    if (m_PrevDS == dataSource)
                    {
                        if (BSInput.s_Shift)
                        {
                            if (m_PrevDS == dataSource)
                            {
                                /*result = */ CalcSelection(0);
                            }
                        }
                        // Substract
                        else if (BSInput.s_Alt)
                        {
                            /*result = */ CalcSelection(1);
                        }
                        // Cross
                        else if (BSInput.s_Control)
                        {
                            /*result = */ CalcSelection(2);
                        }
                        else
                        {
                            ClearSelection(m_Action);
                            /*result = */ CalcSelection(0);
                        }

                        m_PrevDS = dataSource;
                    }
                    else
                    {
                        ClearSelection(m_Action);
                        /*result = */ CalcSelection(0);

                        m_PrevDS = dataSource;
                    }
                }

                m_Selecting = false;
                ResetValue();
            }
        }
        // Other Ajust
        if (AfterSelectionUpdate())
        {
            DoHistory();
        }
    }
Beispiel #6
0
    void Update()
    {
        if (GameConfig.IsInVCE)
        {
            return;
        }

        if (Input.GetKeyDown(KeyCode.O))
        {
            Gen = true;
        }

        if (Gen)
        {
            if (m_Cursor != null)
            {
                Destroy(m_Cursor.gameObject);
            }
            m_Cursor = BIsoCursor.CreateIsoCursor(GameConfig.GetUserDataPath() + BSSaveIsoBrush.s_IsoPath + File_Name + BSSaveIsoBrush.s_Ext);
            m_Rot    = 0;
            Gen      = false;
        }

        if (m_Cursor == null)
        {
            return;
        }

        if (BSInput.s_Cancel)
        {
            Cancel();
            if (onCancelClick != null)
            {
                onCancelClick();
            }
            return;
        }

        if (m_Cursor != null)
        {
            m_Cursor.gameObject.SetActive(true);
        }

        if (m_Cursor.ISO.m_HeadInfo.Mode == EBSVoxelType.Block)
        {
            if (BSMath.RayCastDrawTarget(BSInput.s_PickRay, BuildingMan.Blocks, out m_Target, BSMath.MC_ISO_VALUE, true, BuildingMan.Datas))
            {
                m_Cursor.gameObject.SetActive(true);

                Vector3 offset = Vector3.zero;
                offset.x = (m_Cursor.ISO.m_HeadInfo.xSize) / 2 * BSBlock45Data.s_Scale;
                offset.z = (m_Cursor.ISO.m_HeadInfo.zSize) / 2 * BSBlock45Data.s_Scale;


                if (Input.GetKeyDown(KeyCode.T))
                {
                    m_Rot = ++m_Rot > 3 ? 0 : m_Rot;
                }


                m_Cursor.SetOriginOffset(-offset);
                m_Cursor.transform.rotation = Quaternion.Euler(0, 90 * m_Rot, 0);

                // Adjust Offset
                FocusAjust();

                m_Cursor.transform.position = m_Target.cursor + m_FocusOffset * BSBlock45Data.s_Scale;

                if (Input.GetMouseButtonDown(0))
                {
                    if (BSInput.s_MouseOnUI)
                    {
                        return;
                    }

                    if (m_Cursor.gizmoTrigger.RayCast)
                    {
                        return;
                    }

                    // For History
                    m_OldVoxel.Clear();
                    m_NewVoxel.Clear();
                    m_Indexes.Clear();
                    m_VoxelMap.Clear();

                    m_Cursor.OutputVoxels(Vector3.zero, OnOutputBlocks);

                    // Extra Extendable
                    FindExtraExtendableVoxels(dataSource, m_NewVoxel, m_OldVoxel, m_Indexes, m_VoxelMap);

                    // For History
                    BSAction      action = new BSAction();
                    BSVoxelModify modify = new BSVoxelModify(m_Indexes.ToArray(), m_OldVoxel.ToArray(), m_NewVoxel.ToArray(), BuildingMan.Blocks, EBSBrushMode.Add);
                    if (!modify.IsNull())
                    {
                        action.AddModify(modify);
                    }

                    if (action.Do())
                    {
                        BSHistory.AddAction(action);
                        if (onBrushDo != null)
                        {
                            onBrushDo();
                        }
                    }
                }
            }
            else
            {
                m_Cursor.gameObject.SetActive(false);
            }
        }
        else if (m_Cursor.ISO.m_HeadInfo.Mode == EBSVoxelType.Block)
        {
            if (BSMath.RayCastDrawTarget(BSInput.s_PickRay, BuildingMan.Voxels, out m_Target, 1, true, BuildingMan.Datas))
            {
                m_Cursor.gameObject.SetActive(false);
                Debug.Log("Draw building Iso dont support the voxel");
                return;
            }
            else
            {
                m_Cursor.gameObject.SetActive(false);
            }
        }
    }
Beispiel #7
0
    void AddMode()
    {
        // Set gizmo
        if (pattern != prvePattern)
        {
            if (Gizmo != null)
            {
                Destroy(Gizmo.gameObject);
                Gizmo = null;
            }

            if (pattern.MeshPath != null && pattern.MeshPath != "")
            {
                Gizmo = GameObject.Instantiate(Resources.Load(pattern.MeshPath)) as GameObject;
                Gizmo.transform.parent = transform;
            }


            prvePattern = pattern;
            m_Rot       = 0;
        }


        if (pattern.MeshMat != null && Gizmo != null)
        {
            Renderer gizmo_render = Gizmo.GetComponent <Renderer>();
            if (gizmo_render != null)
            {
                gizmo_render.material = pattern.MeshMat;
            }
        }

        // Ratate the gizmo ?  Only block can rotate
        if (pattern.type == EBSVoxelType.Block)
        {
            if (Input.GetKeyDown(KeyCode.T))
            {
                m_Rot = ++m_Rot > 3 ? 0 : m_Rot;
            }
        }

        // Gizmo rotate
        Vector3 rot_offset = Vector3.zero;

        if (Gizmo != null)
        {
            Quaternion rot = Quaternion.Euler(0, 90 * m_Rot, 0);
            Gizmo.transform.rotation = Quaternion.Euler(0, 90 * m_Rot, 0);
            float half_size = pattern.size * 0.5f;
            rot_offset = (rot * new Vector3(-half_size, -half_size, -half_size) + new Vector3(half_size, half_size, half_size)) * dataSource.Scale;

            // Gizmo scale
            Gizmo.transform.localScale = new Vector3(pattern.size, pattern.size, pattern.size) * dataSource.Scale;
        }


        // default gizmo cube
        GizmoCube.m_VoxelSize = dataSource.Scale;
        GizmoCube.CubeSize    = new IntVector3(pattern.size, pattern.size, pattern.size);
        Vector3 trigget_size = new Vector3(GizmoCube.CubeSize.x * dataSource.Scale,
                                           GizmoCube.CubeSize.y * dataSource.Scale,
                                           GizmoCube.CubeSize.z * dataSource.Scale);

        GizmoTrigger.boxCollider.size   = trigget_size;
        GizmoTrigger.boxCollider.center = trigget_size * 0.5f;

        // Ray cast voxel
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (BSMath.RayCastDrawTarget(ray, dataSource, out m_Target, minvol, true, BuildingMan.Datas))
        {
            // Show the Gizmo
            if (Gizmo != null)
            {
                Gizmo.SetActive(true);
            }
            GizmoCube.gameObject.SetActive(true);

            m_Cursor = CalcCursor(m_Target, dataSource, pattern.size);

            // Gizmo position
            FocusAjust();

            m_Cursor += m_FocusOffset * dataSource.Scale;
            if (Gizmo != null)
            {
                Gizmo.transform.position = m_Cursor + dataSource.Offset + rot_offset;
            }
            GizmoCube.transform.position = m_Cursor + dataSource.Offset;

            // Bursh do
            if (Input.GetMouseButtonDown(0) && !GizmoTrigger.RayCast)
            {
                Do();
            }
        }
    }
Beispiel #8
0
    void SubtractMode()
    {
        m_Rot       = 0;
        prvePattern = null;

        if (Gizmo != null)
        {
            Destroy(Gizmo.gameObject);
            Gizmo = null;
        }

        GizmoCube.gameObject.SetActive(true);

        GizmoCube.m_VoxelSize = dataSource.Scale;
        GizmoCube.CubeSize    = new IntVector3(pattern.size, pattern.size, pattern.size);

        // Ray cast voxel
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (BSMath.RayCastDrawTarget(ray, dataSource, out m_Target, minvol, false))
        {
            // Show the Gizmo
            if (Gizmo != null)
            {
                Gizmo.SetActive(true);
            }
            if (!GizmoCube.gameObject.activeSelf)
            {
                GizmoCube.gameObject.SetActive(true);
            }

            // Cursor position
            m_Cursor = CalcSnapto(m_Target, dataSource, pattern);

            // Gizmo position
            FocusAjust();

            m_Cursor += m_FocusOffset * dataSource.Scale;
            if (Gizmo != null)
            {
                Gizmo.transform.position = m_Cursor + dataSource.Offset;
            }
            GizmoCube.transform.position = m_Cursor + dataSource.Offset;

            // Bursh do
            if (Input.GetMouseButtonDown(0))
            {
                Do();
            }
        }
        else
        {
            if (Gizmo != null)
            {
                Gizmo.SetActive(false);
            }
            if (GizmoCube.gameObject.activeSelf)
            {
                GizmoCube.gameObject.SetActive(false);
            }
        }
    }
Beispiel #9
0
    protected void Update()
    {
        if (dataSource == null)
        {
            return;
        }

        if (pattern == null)
        {
            return;
        }

        if (!ExtraAdjust())
        {
            return;
        }

        if (GameConfig.IsInVCE)
        {
            return;
        }

        gizmoCube.m_VoxelSize = dataSource.Scale;

        if (m_Phase == EPhase.Free)
        {
            if (BSInput.s_MouseOnUI)
            {
                gizmoCube.gameObject.SetActive(false);
                return;
            }

            if (BSInput.s_Cancel)
            {
                ResetDrawing();
            }

            // Ray cast voxel
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            bool ignoreDiagonal = (mode == EBSBrushMode.Add);
            bool cast           = BSMath.RayCastDrawTarget(ray, dataSource, out m_Target, minvol, ignoreDiagonal, BuildingMan.Datas);
            if (cast)
            {
                Vector3 cursor = Vector3.zero;

                if (mode == EBSBrushMode.Add)
                {
                    cursor = CalcCursor(m_Target, dataSource, pattern.size);

                    m_Cursor = m_Target.rch.point;
                }
                else if (mode == EBSBrushMode.Subtract)
                {
                    cursor = CalcSnapto(m_Target, dataSource, pattern);

                    m_Cursor = m_Target.rch.point;
                }
                m_GizmoCursor = cursor;

                _drawGL            = true;
                gizmoCube.CubeSize = new IntVector3(pattern.size, pattern.size, pattern.size);
                gizmoCube.gameObject.SetActive(true);
                gizmoCube.transform.position = cursor + dataSource.Offset;

                UpdateGizmoTrigger();

                float   offset = pattern.size * dataSource.Scale;
                Vector3 begin  = cursor;
                Vector3 end    = begin + new Vector3(offset, offset, offset);
                _glCenter   = cursor + new Vector3(offset, offset, offset) * 0.5f + dataSource.Offset;
                _glCenter.y = begin.y;

                // Click mouse and change phase
                if (Input.GetMouseButtonDown(0))
                {
                    m_Begin   = begin;
                    _beginPos = begin;
                    m_End     = end;

                    m_Phase       = EPhase.DragPlane;
                    _prevMousePos = Input.mousePosition;
                }
            }
            else
            {
                ResetDrawing();
            }

            // Switch the panel
            if (Input.GetKeyDown(KeyCode.G))
            {
                if (DragPlane == ECoordPlane.XZ)
                {
                    DragPlane = ECoordPlane.ZY;
                }
                else if (DragPlane == ECoordPlane.ZY)
                {
                    DragPlane = ECoordPlane.XY;
                }
                else if (DragPlane == ECoordPlane.XY)
                {
                    DragPlane = ECoordPlane.XZ;
                }

                Debug.Log("Switch the drag reference plane : " + DragPlane.ToString());
            }
        }
        else if (m_Phase == EPhase.DragPlane)
        {
            if (BSInput.s_Cancel)
            {
                ResetDrawing();
                return;
            }

            RaycastHit rch;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            float position = 0;

            if (DragPlane == ECoordPlane.XY)
            {
                position = m_Cursor.z;
            }
            else if (DragPlane == ECoordPlane.XZ)
            {
                position = m_Cursor.y;
            }
            else if (DragPlane == ECoordPlane.ZY)
            {
                position = m_Cursor.x;
            }

            if (BSMath.RayCastCoordPlane(ray, DragPlane, position, out rch))
            {
                m_PointBeforeAdjustHeight = rch.point;
                if (!Vector3.Equals(_prevMousePos, Input.mousePosition))
                {
                    Vector3 point = rch.point - dataSource.Offset;


                    if (DragPlane == ECoordPlane.XZ)
                    {
                        // x
                        float x = 0;
                        m_Begin.x = CalcValue(point.x, _beginPos.x, out x);

                        // z
                        float z = 0;
                        m_Begin.z = CalcValue(point.z, _beginPos.z, out z);

                        m_End = new Vector3(x, _beginPos.y + (pattern.size) * dataSource.Scale, z);
                        m_End = Clamp(m_Begin, m_End);
                    }
                    else if (DragPlane == ECoordPlane.XY)
                    {
                        // x
                        float x = 0;
                        m_Begin.x = CalcValue(point.x, _beginPos.x, out x);

                        // y
                        float y = 0;
                        m_Begin.y = CalcValue(point.y, _beginPos.y, out y);

                        m_End = new Vector3(x, y, _beginPos.z + (pattern.size) * dataSource.Scale);
                        m_End = Clamp(m_Begin, m_End);
                    }
                    else if (DragPlane == ECoordPlane.ZY)
                    {
                        // y
                        float y = 0;
                        m_Begin.y = CalcValue(point.y, _beginPos.y, out y);

                        // z
                        float z = 0;
                        m_Begin.z = CalcValue(point.z, _beginPos.z, out z);

                        m_End = new Vector3(_beginPos.x + (pattern.size) * dataSource.Scale, y, z);
                        m_End = Clamp(m_Begin, m_End);
                    }

                    // other phase Drag plane
                    DragPlaneExtraDo(DragPlane);

                    gizmoCube.transform.position = Min + dataSource.Offset;

                    gizmoCube.CubeSize = new IntVector3((int)Size.x, (int)Size.y, (int)Size.z);

                    UpdateGizmoTrigger();
                }



                // Click mouse and change phase
                if (Input.GetMouseButtonUp(0))
                {
                    m_Phase       = EPhase.AdjustHeight;
                    _prevMousePos = new Vector3(-100, -100, -100);
                }
            }
        }
        else if (m_Phase == EPhase.AdjustHeight)
        {
            if (BSInput.s_Cancel)
            {
                ResetDrawing();
                return;
            }

            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

//			ECoordAxis axis = ECoordAxis.Y;
            if (DragPlane == ECoordPlane.XZ)
            {
                float adjustHeight = m_PointBeforeAdjustHeight.y;
                BSMath.RayAdjustHeight(ray, ECoordAxis.Y, m_PointBeforeAdjustHeight, out adjustHeight);

                // y
                float y = 0;
                m_Begin.y = CalcValue(adjustHeight, _beginPos.y, out y);
                m_End.y   = y + m_EndOffset.y;
            }
            else if (DragPlane == ECoordPlane.XY)
            {
                float adjustHeight = m_PointBeforeAdjustHeight.z;
                BSMath.RayAdjustHeight(ray, ECoordAxis.Z, m_PointBeforeAdjustHeight, out adjustHeight);


                // z
                float z = 0;
                m_Begin.z = CalcValue(adjustHeight, _beginPos.z, out z);
                m_End.z   = z + m_EndOffset.z;
            }
            else if (DragPlane == ECoordPlane.ZY)
            {
                float adjustHeight = m_PointBeforeAdjustHeight.x;
                BSMath.RayAdjustHeight(ray, ECoordAxis.X, m_PointBeforeAdjustHeight, out adjustHeight);

                // x
                float x = 0;
                m_Begin.x = CalcValue(adjustHeight, _beginPos.x, out x);

                m_End.x = x + m_EndOffset.x;
            }

            m_End = Clamp(m_Begin, m_End);

            // Other adjustHeight
            AdjustHeightExtraDo(DragPlane);


            gizmoCube.transform.position = Min + dataSource.Offset;

            gizmoCube.CubeSize = new IntVector3((int)Size.x, (int)Size.y, (int)Size.z);

            UpdateGizmoTrigger();

            // Click mouse and change phase
            //if (Input.GetMouseButtonDown(0))
            if (PeInput.Get(PeInput.LogicFunction.Build))
            {
                Do();
                m_Phase = EPhase.Free;
            }
        }


        AfterDo();
    }
Beispiel #10
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);
//							}
//						}
//					}
//
//				}
//			}
        }
    }