public override VCComponentData Get()
    {
        VCDecalData data = m_Data.Copy() as VCDecalData;

        data.m_Position = m_PositionInput.Vector;
        data.m_Rotation = VCEMath.NormalizeEulerAngle(m_RotationInput.Vector);
        Vector3 scale = m_ScaleInput.Vector;

        data.m_Size     = scale.x;
        data.m_Depth    = scale.z;
        scale.y         = scale.x;
        data.m_Mirrored = m_MirroredCheck.isChecked;
        data.m_Color    = m_ColorPicker.FinalColor;
        if (m_Shader0Check.isChecked)
        {
            data.m_ShaderIndex = 0;
        }
        else if (m_Shader1Check.isChecked)
        {
            data.m_ShaderIndex = 1;
        }
        else
        {
            data.m_ShaderIndex = 0;
        }

        data.Validate();
        m_PositionInput.Vector = data.m_Position;
        m_RotationInput.Vector = data.m_Rotation;
        m_ScaleInput.Vector    = scale;

        return(data);
    }
Exemplo n.º 2
0
 public static bool RayAdjustHeight(Ray ray, Vector3 basepoint, out float height)
 {
     height = basepoint.y;
     if (!VCEditor.DocumentOpen())
     {
         return(false);
     }
     ray = VCEMath.TransformRayToIsoCoord(ray);
     if (Mathf.Abs(ray.direction.x) < 0.001f && Mathf.Abs(ray.direction.z) < 0.001f)
     {
         return(false);
     }
     else
     {
         Vector3 horz      = Vector3.Cross(Vector3.up, ray.direction).normalized;
         Plane   ray_plane = new Plane(ray.origin, ray.GetPoint(10), ray.origin + horz * 10);
         Ray     vert      = new Ray(basepoint + Vector3.up * 2000, Vector3.down);
         float   enter     = 0;
         if (ray_plane.Raycast(vert, out enter))
         {
             height = vert.GetPoint(enter).y;
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Exemplo n.º 3
0
    public override void UpdateEntity(bool for_editor)
    {
        if (for_editor)
        {
            VCEComponentTool tool = m_Entity.GetComponent <VCEComponentTool>();
            tool.m_Data = this;
        }
        m_Rotation = VCEMath.NormalizeEulerAngle(m_Rotation);
        m_Entity.transform.localPosition    = m_Position;
        m_Entity.transform.localEulerAngles = m_Rotation;
        m_Entity.transform.localScale       = m_Scale;
        VCDecalHandler dh = m_Entity.GetComponent <VCDecalHandler>();

        if (for_editor)
        {
            dh.m_Guid       = m_Guid;
            dh.m_Iso        = null;
            dh.m_AssetIndex = -1;
        }
        else
        {
            dh.m_Guid       = 0;
            dh.m_Iso        = m_CurrIso;
            dh.m_AssetIndex = m_AssetIndex;
        }
        dh.m_Size        = m_Size;
        dh.m_Depth       = m_Depth;
        dh.m_Mirrored    = m_Mirrored;
        dh.m_ShaderIndex = m_ShaderIndex;
        dh.m_Color       = m_Color;
    }
Exemplo n.º 4
0
 public List <VCEComponentTool> MirrorImage(VCEComponentTool c)
 {
     VCEditor.s_Mirror.CalcPrepare(VCEditor.s_Scene.m_Setting.m_VoxelSize);
     // Mirror
     if (VCEditor.s_Mirror.Enabled_Masked)
     {
         List <VCEComponentTool> list_ret = new List <VCEComponentTool> ();
         VCEditor.s_Mirror.MirrorComponent(c.m_Data);
         for (int i = 1; i < VCEditor.s_Mirror.OutputCnt; ++i)
         {
             VCComponentData        image       = VCEditor.s_Mirror.ComponentOutput[i];
             List <VCComponentData> projections = VCEditor.s_Scene.m_IsoData.FindComponentsAtPos(image.m_Position, image.m_ComponentId);
             foreach (VCComponentData iter in projections)
             {
                 if (!VCEMath.IsEqualRotation(iter.m_Rotation, image.m_Rotation))
                 {
                     continue;
                 }
                 if (iter.m_Scale != image.m_Scale)
                 {
                     continue;
                 }
                 if (iter.m_Visible != image.m_Visible)
                 {
                     continue;
                 }
                 if (image is IVCMultiphaseComponentData && iter is IVCMultiphaseComponentData)
                 {
                     if ((image as IVCMultiphaseComponentData).Phase != (iter as IVCMultiphaseComponentData).Phase)
                     {
                         continue;
                     }
                 }
                 VCEComponentTool imct = iter.m_Entity.GetComponent <VCEComponentTool>();
                 if (imct == null)
                 {
                     continue;
                 }
                 if (imct == c)
                 {
                     continue;
                 }
                 list_ret.Add(imct);
             }
         }
         return(list_ret);
     }
     // No mirror
     else
     {
         return(new List <VCEComponentTool> ());
     }
 }
Exemplo n.º 5
0
    public override void UpdateEntity(bool for_editor)
    {
        if (for_editor)
        {
            VCEComponentTool tool = m_Entity.GetComponent <VCEComponentTool>();
            tool.m_Data = this;
        }
        m_Rotation = VCEMath.NormalizeEulerAngle(m_Rotation);
        m_Entity.transform.localPosition    = m_Position;
        m_Entity.transform.localEulerAngles = m_Rotation;
        m_Entity.transform.localScale       = m_Scale;

        VCPSimpleLight func = m_Entity.GetComponent <VCPSimpleLight>();

        if (func != null)
        {
            func.color = m_Color;
        }

        Renderer[] rs = m_Entity.GetComponentsInChildren <Renderer>(true);
        foreach (Renderer r in rs)
        {
            if (r is TrailRenderer)
            {
                r.enabled = true;
            }
            else if (r is ParticleRenderer)
            {
                r.enabled = true;
            }
            else if (r is ParticleSystemRenderer)
            {
                r.enabled = true;
            }
            else if (r is LineRenderer)
            {
                r.enabled = true;
            }
            else if (r is SpriteRenderer)
            {
                r.enabled = true;
            }
            else
            {
                r.enabled = m_Visible;
            }
        }
    }
    public override VCComponentData Get()
    {
        VCFixedHandPartData data = m_Data.Copy() as VCFixedHandPartData;

        data.m_Position = m_PositionInput.Vector;
        data.m_Rotation = VCEMath.NormalizeEulerAngle(m_RotationInput.Vector);
        data.m_Visible  = m_VisibleCheck ? m_VisibleCheck.isChecked : true;
        data.m_LeftHand = m_Phase0Check.isChecked;
        data.Validate();
        m_PositionInput.Vector = data.m_Position;
        m_RotationInput.Vector = data.m_Rotation;
        if (m_VisibleCheck)
        {
            m_VisibleCheck.isChecked = data.m_Visible;
        }

        return(data);
    }
Exemplo n.º 7
0
    public override VCComponentData Get()
    {
        VCObjectLightData data = m_Data.Copy() as VCObjectLightData;

        data.m_Position = m_PositionInput.Vector;
        data.m_Rotation = VCEMath.NormalizeEulerAngle(m_RotationInput.Vector);
        data.m_Scale    = m_ScaleInput.Vector;
        data.m_Color    = m_ColorPicker.FinalColor;
        data.m_Visible  = m_VisibleCheck.isChecked;

        data.Validate();
        m_PositionInput.Vector   = data.m_Position;
        m_RotationInput.Vector   = data.m_Rotation;
        m_ScaleInput.Vector      = data.m_Scale;
        m_ColorPicker.FinalColor = data.m_Color;
        m_VisibleCheck.isChecked = data.m_Visible;

        return(data);
    }
Exemplo n.º 8
0
    // Paint a specified mesh position
    void PaintPosition(Vector3 wpos, Vector3 normal)
    {
        float voxel_size = VCEditor.s_Scene.m_Setting.m_VoxelSize;

        VCEditor.s_Mirror.CalcPrepare(voxel_size);

        // calculate the right & up axis
        transform.rotation = Quaternion.LookRotation(-normal);
        Vector3 right = transform.right;
        Vector3 up    = transform.up;

        transform.rotation = Quaternion.identity;

        float   r     = Mathf.Clamp(m_Radius, 0.25f, 16.0f);
        Vector3 pivot = wpos + normal * voxel_size;

        for (float a = -r; a <= r + 0.001f; a += 0.25f)
        {
            for (float b = -r; b <= r + 0.001f; b += 0.25f)
            {
                if (a * a + b * b > r * r)
                {
                    continue;
                }
                float strength = 1;
                if (r > 0.75f && m_Hardness < 1)
                {
                    strength = (1 - Mathf.Sqrt(a * a + b * b) / r) / (1 - m_Hardness);
                    strength = Mathf.Pow(strength, 2);
                    strength = Mathf.Clamp01(strength);
                }
                Vector3    origin = pivot + (a * right + b * up) * voxel_size;
                Ray        ray    = new Ray(origin, -normal);
                RaycastHit rch;
                if (VCEMath.RayCastMesh(ray, out rch, voxel_size * 2))
                {
                    Vector3    iso_pos = rch.point / VCEditor.s_Scene.m_Setting.m_VoxelSize;
                    MeshFilter mf      = rch.collider.GetComponent <MeshFilter>();
                    ColorPosition(iso_pos, mf, strength * m_Strength);
                }
            }
        }
    }
    public override VCComponentData Get()
    {
        VCGeneralPartData data = m_Data.Copy() as VCGeneralPartData;

        data.m_Position = m_PositionInput.Vector;
        data.m_Rotation = VCEMath.NormalizeEulerAngle(m_RotationInput.Vector);
        data.m_Visible  = m_VisibleCheck ? m_VisibleCheck.isChecked : true;
        data.Validate();
        data.m_ExtendData      = VCEditor.Instance.m_UI.bonePanel.ArmorPartIndex;
        m_PositionInput.Vector = data.m_Position;
        m_RotationInput.Vector = data.m_Rotation;
        if (m_VisibleCheck)
        {
            m_VisibleCheck.isChecked = data.m_Visible;
        }
        m_ArmorPartIndex = data.m_ExtendData;

        return(data);
    }
Exemplo n.º 10
0
 void Update()
 {
     VCEMath.DrawTarget dtar;
     if (VCEInput.s_MouseOnUI)
     {
         m_Center = InvalidPos;
     }
     else
     {
         if (VCEMath.RayCastDrawTarget(VCEInput.s_PickRay, out dtar, 1))
         {
             m_Center.x = dtar.snapto.x;
             m_Center.y = dtar.snapto.y;
             m_Center.z = dtar.snapto.z;
         }
         else
         {
             m_Center = InvalidPos;
         }
     }
 }
Exemplo n.º 11
0
 void KeyFocus()
 {
     if ((Input.GetKeyDown(KeyCode.F) || VCEInput.s_RightDblClick) && !UICamera.inputHasFocus && !Input.GetMouseButton(0) && !s_ProtectLock0)
     {
         VCEMath.DrawTarget dtar;
         if (VCEMath.RayCastDrawTarget(VCEInput.s_PickRay, out dtar, VCEMath.MC_ISO_VALUE))
         {
             Vector3 newtar = (dtar.snapto.ToVector3() + dtar.cursor.ToVector3() + Vector3.one) * 0.5f * s_Scene.m_Setting.m_VoxelSize;
             // New look distance to keep the origin distance
             VCECamera cam_scr = m_MainCamera.GetComponent <VCECamera>();
             float     dist    = cam_scr.Distance;
             // Maximum distance
             float maxdist = s_Scene.m_Setting.m_VoxelSize * 10.0f;
             if (dist > maxdist)
             {
                 dist = maxdist;
             }
             cam_scr.SetTarget(newtar);
             cam_scr.SetDistance(dist);
         }
     }
 }
    public override VCComponentData Get()
    {
        VCObjectPivotData data = m_Data.Copy() as VCObjectPivotData;

        data.m_Position = m_PositionInput.Vector;
        data.m_Rotation = VCEMath.NormalizeEulerAngle(m_RotationInput.Vector);
        data.m_Scale    = m_ScaleInput.Vector;
        data.m_Visible  = m_VisibleCheck.isChecked;
        int ang = Float01ToIntAngle(m_AnlgeSlider.sliderValue);

        data.m_PivotAng = ang;

        data.Validate();
        m_PositionInput.Vector   = data.m_Position;
        m_RotationInput.Vector   = data.m_Rotation;
        m_ScaleInput.Vector      = data.m_Scale;
        m_VisibleCheck.isChecked = data.m_Visible;
        ang = data.m_PivotAng;
        m_AnlgeLable.text         = ang.ToString();
        m_AnlgeSlider.sliderValue = Convert.ToSingle(ang) / 720 + 0.5f;

        return(data);
    }
Exemplo n.º 13
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);
        }
    }
Exemplo n.º 14
0
    void Update()
    {
        // Common draw target
        VCEMath.RayCastDrawTarget(VCEInput.s_PickRay, out m_Target, 1, true);

        // Inspector
        if (VCEditor.s_Scene.m_IsoData.m_Voxels.Count > 0)
        {
            ShowMainInspector();
        }
        else
        {
            HideMainInspector();
        }

        // Cancel
        if (VCEInput.s_Cancel)
        {
#if CAN_CANCELALLMETHOD
            if (m_MethodExec == null)
            {
                m_SelectionMgr.ClearSelection();
            }
            else
            {
                m_MainInspector.GetComponent <VCEUISelectVoxelInspector>().CancelAllMethod();
            }
#else
            m_SelectionMgr.ClearSelection();
#endif
        }

        // Execute selection method
        if (m_MethodExec != null)
        {
            m_MethodExec.MainMethod();
            if (m_MethodExec.m_NeedUpdate)
            {
                m_SelectionMgr.RebuildSelectionBoxes();
                m_MethodExec.m_NeedUpdate = false;
            }
        }
        else
        {
            VCEditor.Instance.m_NearVoxelIndicator.enabled = false;
        }

        if (!m_MainInspector.activeInHierarchy)
        {
            m_MainInspector.GetComponent <VCEUISelectVoxelInspector>().Update();
        }

        if (m_SelectionMgr.m_Selection.Count > 0)
        {
            if (VCEInput.s_Shift && VCEInput.s_Left)
            {
                ExtrudeSelection(-1, 0, 0);
                VCEStatusBar.ShowText("Extrude left".ToLocalizationString(), 2);
            }
            if (VCEInput.s_Shift && VCEInput.s_Right)
            {
                ExtrudeSelection(1, 0, 0);
                VCEStatusBar.ShowText("Extrude right".ToLocalizationString(), 2);
            }
            if (VCEInput.s_Shift && VCEInput.s_Up)
            {
                ExtrudeSelection(0, 1, 0);
                VCEStatusBar.ShowText("Extrude up".ToLocalizationString(), 2);
            }
            if (VCEInput.s_Shift && VCEInput.s_Down)
            {
                ExtrudeSelection(0, -1, 0);
                VCEStatusBar.ShowText("Extrude down".ToLocalizationString(), 2);
            }
            if (VCEInput.s_Shift && VCEInput.s_Forward)
            {
                ExtrudeSelection(0, 0, 1);
                VCEStatusBar.ShowText("Extrude forward".ToLocalizationString(), 2);
            }
            if (VCEInput.s_Shift && VCEInput.s_Back)
            {
                ExtrudeSelection(0, 0, -1);
                VCEStatusBar.ShowText("Extrude back".ToLocalizationString(), 2);
            }
        }
        // Tips
        if (!Input.GetMouseButton(0) && VCEditor.s_Scene.m_IsoData.IsPointIn(m_Target.snapto))
        {
            tips_counter -= Time.deltaTime;
        }
    }
Exemplo n.º 15
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);
        }
    }
Exemplo n.º 16
0
    // Update is called once per frame
    protected void Update()
    {
        if (!VCEditor.DocumentOpen() ||
            VCEditor.SelectedVoxelType < 0)
        {
            m_Phase = EPhase.Free;
            m_GizmoCube.gameObject.SetActive(false);
            return;
        }

        float voxel_size = VCEditor.s_Scene.m_Setting.m_VoxelSize;

        m_GizmoCube.m_VoxelSize = voxel_size;

        ExtraAdjust();

        if (m_Phase == EPhase.Free)
        {
            if (!VCEInput.s_MouseOnUI)
            {
                // Cancel
                if (VCEInput.s_Cancel)
                {
                    ResetDrawing();
                    Cancel();
                }
                VCEMath.RayCastDrawTarget(VCEInput.s_PickRay, out m_Target, VCEMath.MC_ISO_VALUE);
                if (VCEditor.s_Scene.m_IsoData.IsPointIn(m_Target.cursor))
                {
                    m_GizmoCube.CubeSize           = IntVector3.One;
                    m_GizmoCube.transform.position = m_Target.cursor.ToVector3() * voxel_size;
                    m_GizmoCube.gameObject.SetActive(true);
                    if (Input.GetMouseButtonDown(0))
                    {
                        m_Begin = new IntVector3(m_Target.cursor);
                        m_End   = new IntVector3(m_Target.cursor);
                        m_Phase = EPhase.DragPlane;
                        VCEditor.Instance.m_UI.DisableFunctions();
                        VCEditor.s_ProtectLock0 = true;
                        VCEStatusBar.ShowText("Drag an area".ToLocalizationString(), 2);
                    }
                }
                else
                {
                    m_GizmoCube.gameObject.SetActive(false);
                }
            }
            else
            {
                m_GizmoCube.gameObject.SetActive(false);
            }
            VCEditor.Instance.m_NearVoxelIndicator.enabled = true;
        }
        else if (m_Phase == EPhase.DragPlane)
        {
            // Cancel
            if (VCEInput.s_Cancel)
            {
                ResetDrawing();
            }
            RaycastHit rch;
            if (VCEMath.RayCastCoordPlane(VCEInput.s_PickRay, ECoordPlane.XZ, m_Begin.y, out rch))
            {
                m_End = new IntVector3(Mathf.FloorToInt(rch.point.x), m_Begin.y, Mathf.FloorToInt(rch.point.z));
                VCEditor.s_Scene.m_IsoData.ClampPointI(m_End, m_Begin.x < 0.5f * VCEditor.s_Scene.m_IsoData.m_HeadInfo.xSize);
                m_PointBeforeAdjustHeight = rch.point;
                VCEditor.s_Scene.m_IsoData.ClampPointI(m_End, m_Begin.x < 0.5f * VCEditor.s_Scene.m_IsoData.m_HeadInfo.xSize);
                m_GizmoCube.CubeSize           = Size;
                m_GizmoCube.transform.position = Min.ToVector3() * voxel_size;
            }
            else
            {
                ResetDrawing();
            }
            if (Input.GetMouseButtonUp(0))
            {
                m_Phase = EPhase.AdjustHeight;
                VCEStatusBar.ShowText("Adjust height".ToLocalizationString(), 2);
            }
            VCEditor.Instance.m_NearVoxelIndicator.enabled = false;
        }
        else if (m_Phase == EPhase.AdjustHeight)
        {
            // Cancel
            if (VCEInput.s_Cancel)
            {
                ResetDrawing();
            }

            float height = m_PointBeforeAdjustHeight.y;
            VCEMath.RayAdjustHeight(VCEInput.s_PickRay, m_PointBeforeAdjustHeight, out height);
            m_End.y = Mathf.FloorToInt(height + 0.3f);

            VCEditor.s_Scene.m_IsoData.ClampPointI(m_End);
            m_GizmoCube.CubeSize           = Size;
            m_GizmoCube.transform.position = Min.ToVector3() * voxel_size;

            // Do the brush
            if (Input.GetMouseButtonDown(0))
            {
                m_Phase = EPhase.Drawing;
                Do();
                VCEStatusBar.ShowText("Done".ToLocalizationString(), 2);
            }
            VCEditor.Instance.m_NearVoxelIndicator.enabled = false;
        }
    }
Exemplo n.º 17
0
    void Update()
    {
        if (!VCEditor.DocumentOpen())
        {
            return;
        }

        // Check 's_LastCreate'
        if (s_LastCreate != null)
        {
            ClearSelection();
            SelectInfo si = new SelectInfo();
            si.m_Component = s_LastCreate;
            m_Selection.Add(si);
            OnSelectionChange();
        }

        VCEditor.s_ProtectLock0 = UsingGizmo;
        NormalizeSelection();

        // Update Pick Order
        Vector3 mousePos = Input.mousePosition;

        if ((mousePos - lastMousePos).magnitude > 3.1f)
        {
            pick_order   = 0;
            lastMousePos = mousePos;
        }

        #region PART_DESC
        // Part Description Board
        if (m_DescBoard != null)
        {
            m_DescBoard.m_Position = Vector3.Lerp(m_DescBoard.m_Position, VCEInput.s_PickRay.GetPoint(1.5f), 0.5f);
            List <VCEComponentTool> pickall = new List <VCEComponentTool> ();
            if (!UsingGizmo && !VCEInput.s_MouseOnUI)
            {
                pickall = VCEMath.RayPickComponents(VCEInput.s_PickRay);
            }
            List <VCPart> pps = new List <VCPart> ();
            Vector3       v   = Vector3.zero;
            if (pickall.Count > 0)
            {
                v = pickall[0].transform.localPosition;
            }
            foreach (VCEComponentTool ct in pickall)
            {
                if (Vector3.Distance(ct.transform.localPosition, v) > VCEditor.s_Scene.m_Setting.m_VoxelSize * 2)
                {
                    continue;
                }
                VCPart pp = ct.GetComponent <VCPart>();
                if (pp != null)
                {
                    pps.Add(pp);
                }
            }
            if (pickall.Count > 0)
            {
                m_DescBoard.FadeIn();
                VCEditor.Instance.m_UI.m_HoloBoardCamera.enabled = true;
            }
            else
            {
                VCEditor.Instance.m_UI.m_HoloBoardCamera.enabled = false;
                m_DescBoard.FadeOut();
            }
            pickall.Clear();
            VCEditor.Instance.m_UI.m_PartDescList.SyncList(pps);
            pps.Clear();
            pickall = null;
            pps     = null;
        }
        #endregion

        // Pick Component
        VCEComponentTool picked = null;
        if (!VCEInput.s_MouseOnUI && !m_MouseOnGizmo)
        {
            picked = VCEMath.RayPickComponent(VCEInput.s_PickRay, pick_order);
        }
        if (Input.GetMouseButtonDown(0) && !VCEInput.s_MouseOnUI && !m_MouseOnGizmo)
        {
            if (!VCEInput.s_Shift && !VCEInput.s_Control && !VCEInput.s_Alt)
            {
                m_Selection.Clear();
            }
            if (picked != null)
            {
                SelectInfo si = FindSelected(picked);
                if (si != null)
                {
                    m_Selection.Remove(si);
                }
                else
                {
                    si             = new SelectInfo();
                    si.m_Component = picked;
                    List <SelectInfo> del_list = new List <SelectInfo> ();
                    foreach (SelectInfo sel in m_Selection)
                    {
                        VCEComponentTool        ct     = sel.m_Component;
                        List <VCEComponentTool> images = MirrorImage(ct);
                        if (images.Contains(si.m_Component))
                        {
                            del_list.Add(sel);
                        }
                    }
                    m_Selection.Add(si);
                    foreach (SelectInfo del in del_list)
                    {
                        m_Selection.Remove(del);
                    }
                }
                pick_order++;
            }
            OnSelectionChange();
        }

        // Update bound color & highlight
        foreach (VCComponentData cd in VCEditor.s_Scene.m_IsoData.m_Components)
        {
            VCEComponentTool c = cd.m_Entity.GetComponent <VCEComponentTool>();
            c.m_SelBound.enabled = true;
            c.m_SelBound.GetComponent <Collider>().enabled = true;
            c.m_SelBound.m_Highlight  = (c == picked);
            c.m_SelBound.m_BoundColor = GLComponentBound.s_Blue;
        }

        // Update selection and mirror's bound color
        if (m_Selection.Count > 0)
        {
            VCEditor.s_Mirror.CalcPrepare(VCEditor.s_Scene.m_Setting.m_VoxelSize);
            foreach (SelectInfo si in m_Selection)
            {
                VCEComponentTool        c       = si.m_Component;
                List <VCEComponentTool> mirrors = MirrorImage(c);
                foreach (VCEComponentTool m in mirrors)
                {
                    m.m_SelBound.m_BoundColor = GLComponentBound.s_Orange;
                }
            }
            foreach (SelectInfo si in m_Selection)
            {
                VCEComponentTool c = si.m_Component;
                c.m_SelBound.m_BoundColor = GLComponentBound.s_Yellow;
            }
        }

        // Update Inspectors
        if (m_Selection.Count < 1)
        {
            HideInspectors();
        }
        else if (m_Selection.Count == 1)
        {
            ShowMainInspector();

            VCEUISelectComponentInspector sci = m_MainInspector.GetComponent <VCEUISelectComponentInspector>();
            if (m_Selection[0].m_Component != null)
            {
                sci.m_SelectInfo.text = m_Selection[0].m_Component.gameObject.name;
            }
            else
            {
                sci.m_SelectInfo.text = "< Deleted >";
            }
        }
        else
        {
            ShowMainInspector();
            HideDataInspector();
            VCEUISelectComponentInspector sci = m_MainInspector.GetComponent <VCEUISelectComponentInspector>();
            sci.m_SelectInfo.text = m_Selection.Count.ToString() + " " + "objects".ToLocalizationString() + " " + "selected".ToLocalizationString();
        }

        // Transform Gizmos
        if (m_Selection.Count > 0)
        {
            Vector3 avePos  = Vector3.zero;
            int     rotmask = 7;
            foreach (SelectInfo si in m_Selection)
            {
                avePos += si.m_Component.transform.position;
                VCPartData part_data = si.m_Component.m_Data as VCPartData;
                if (part_data != null)
                {
                    rotmask &= VCConfig.s_PartTypes[si.m_Component.m_Data.m_Type].m_RotateMask;
                }
            }
            avePos /= ((float)m_Selection.Count);
            m_MovingGizmo.transform.position   = avePos;
            m_RotatingGizmo.transform.position = avePos;
            m_MovingGizmo.gameObject.SetActive(VCEditor.TransformType == EVCETransformType.Move);
            m_RotatingGizmo.gameObject.SetActive(VCEditor.TransformType == EVCETransformType.Rotate);
            m_RotatingGizmo.m_AxisMask = rotmask;
        }
        else
        {
            m_MovingGizmo.gameObject.SetActive(false);
            m_RotatingGizmo.gameObject.SetActive(false);
        }
    }
Exemplo n.º 18
0
    public static bool RayCastDrawTarget(Ray ray, out DrawTarget target, int minvol, bool voxelbest = false)
    {
        target = new DrawTarget();
        if (!VCEditor.DocumentOpen())
        {
            return(false);
        }
        // Cast grid and voxel above minvol
        RaycastHit rch_voxel    = new RaycastHit();
        RaycastHit rch_grid     = new RaycastHit();
        float      dist_voxel   = 10000;
        float      dist_grid    = 10000;
        bool       to_cast_grid = true;

        if (VCEMath.RayCastVoxel(VCEInput.s_PickRay, out rch_voxel, minvol))
        {
            dist_voxel = rch_voxel.distance;
            if (voxelbest)
            {
                to_cast_grid = false;
            }
        }

        if (to_cast_grid && VCEMath.RayCastGrid(VCEInput.s_PickRay, out rch_grid))
        {
            if (rch_grid.normal.y > 0)
            {
                dist_grid = rch_grid.distance;
            }
        }

        // cast voxel
        if (dist_voxel < dist_grid)
        {
            target.rch    = rch_voxel;
            target.snapto = new IntVector3(Mathf.FloorToInt(rch_voxel.point.x - rch_voxel.normal.x * 0.5f),
                                           Mathf.FloorToInt(rch_voxel.point.y - rch_voxel.normal.y * 0.5f),
                                           Mathf.FloorToInt(rch_voxel.point.z - rch_voxel.normal.z * 0.5f));
            target.cursor = new IntVector3(Mathf.FloorToInt(rch_voxel.point.x + rch_voxel.normal.x * 0.5f),
                                           Mathf.FloorToInt(rch_voxel.point.y + rch_voxel.normal.y * 0.5f),
                                           Mathf.FloorToInt(rch_voxel.point.z + rch_voxel.normal.z * 0.5f));
            return(true);
        }
        // cast grid
        else if (dist_grid < dist_voxel)
        {
            target.rch    = rch_grid;
            target.snapto = new IntVector3(Mathf.FloorToInt(rch_grid.point.x - rch_grid.normal.x * 0.5f),
                                           Mathf.FloorToInt(rch_grid.point.y - rch_grid.normal.y * 0.5f),
                                           Mathf.FloorToInt(rch_grid.point.z - rch_grid.normal.z * 0.5f));
            target.cursor = new IntVector3(Mathf.FloorToInt(rch_grid.point.x + rch_grid.normal.x * 0.5f),
                                           Mathf.FloorToInt(rch_grid.point.y + rch_grid.normal.y * 0.5f),
                                           Mathf.FloorToInt(rch_grid.point.z + rch_grid.normal.z * 0.5f));
            if (VCEditor.s_Scene.m_IsoData.GetVoxel(VCIsoData.IPosToKey(target.cursor)).Volume > VCEMath.MC_ISO_VALUE)
            {
                target.cursor = null;
                return(false);
            }
            return(true);
        }
        // cast nothing
        else
        {
            target.rch    = new RaycastHit();
            target.snapto = null;
            target.cursor = null;
            return(false);
        }
    }
Exemplo n.º 19
0
    // Submit this selecting action
    protected override void Submit()
    {
        m_Iso.ClampPointI(m_Begin);
        m_Iso.ClampPointI(m_End);
        IntVector3 iMin = new IntVector3(0, 0, 0);
        IntVector3 iMax = new IntVector3(0, 0, 0);

        iMin.x = Mathf.Min(m_Begin.x, m_End.x);
        iMin.y = Mathf.Min(m_Begin.y, m_End.y);
        iMin.z = Mathf.Min(m_Begin.z, m_End.z);
        iMax.x = Mathf.Max(m_Begin.x, m_End.x);
        iMax.y = Mathf.Max(m_Begin.y, m_End.y);
        iMax.z = Mathf.Max(m_Begin.z, m_End.z);

        // Calculate feather effect bound
        IntVector3 fMin = new IntVector3(0, 0, 0);
        IntVector3 fMax = new IntVector3(0, 0, 0);

        fMin.x = iMin.x - m_FeatherLength; fMin.y = iMin.y - m_FeatherLength; fMin.z = iMin.z - m_FeatherLength;
        fMax.x = iMax.x + m_FeatherLength; fMax.y = iMax.y + m_FeatherLength; fMax.z = iMax.z + m_FeatherLength;
        if (m_PlaneFeather)
        {
            switch (m_Coord)
            {
            case ECoordPlane.XY:
                fMin.z = iMin.z;
                fMax.z = iMax.z;
                break;

            case ECoordPlane.XZ:
                fMin.y = iMin.y;
                fMax.y = iMax.y;
                break;

            case ECoordPlane.ZY:
                fMin.x = iMin.x;
                fMax.x = iMax.x;
                break;
            }
        }
        m_Iso.ClampPointI(fMin);
        m_Iso.ClampPointI(fMax);

        // Select
        if (!VCEInput.s_Shift && !VCEInput.s_Alt && !VCEInput.s_Control)
        {
            m_Selection.Clear();
        }

        for (int x = fMin.x; x <= fMax.x; ++x)
        {
            for (int y = fMin.y; y <= fMax.y; ++y)
            {
                for (int z = fMin.z; z <= fMax.z; ++z)
                {
                    int poskey = VCIsoData.IPosToKey(x, y, z);
                    if (m_Iso.GetVoxel(poskey).Volume < 1)
                    {
                        continue;
                    }
                    int old_sv   = 0;
                    int alter_sv = (m_FeatherLength == 0) ? (255) : ((int)(VCEMath.BoxFeather(new IntVector3(x, y, z), iMin, iMax, m_FeatherLength) * 255.0f));
                    int new_sv   = 0;
                    if (alter_sv < 1)
                    {
                        continue;
                    }

                    if (m_Selection.ContainsKey(poskey))
                    {
                        old_sv = m_Selection[poskey];
                    }
                    if (VCEInput.s_Shift)
                    {
                        new_sv = old_sv + alter_sv;
                    }
                    else if (VCEInput.s_Alt)
                    {
                        new_sv = old_sv - alter_sv;
                    }
                    else if (VCEInput.s_Control)
                    {
                        new_sv = Mathf.Abs(old_sv - alter_sv);
                    }
                    else
                    {
                        new_sv = alter_sv;
                    }
                    new_sv = Mathf.Clamp(new_sv, 0, 255);
                    if (new_sv < 1)
                    {
                        m_Selection.Remove(poskey);
                    }
                    else if (old_sv < 1)
                    {
                        m_Selection.Add(poskey, (byte)new_sv);
                    }
                    else
                    {
                        m_Selection[poskey] = (byte)new_sv;
                    }

                    if (m_MaterialSelect)
                    {
                        VCVoxel vcv = m_Iso.GetVoxel(poskey);
                        if (m_Iso.m_Materials[vcv.Type] != VCEditor.SelectedMaterial)
                        {
                            m_Selection.Remove(poskey);
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 20
0
    public void ApplyInspectorChange()
    {
        if (m_Selection.Count != 1)
        {
            return;
        }
        if (m_DataInspector == null)
        {
            return;
        }

        VCEditor.s_Mirror.CalcPrepare(VCEditor.s_Scene.m_Setting.m_VoxelSize);
        m_Action = new VCEAction();
        VCComponentData old_data = m_Selection[0].m_Component.m_Data;
        VCComponentData new_data = m_DataInspector.GetComponent <VCEUIComponentInspector>().Get();

        // Mirror
        if (VCEditor.s_Mirror.Enabled_Masked)
        {
            VCComponentData[] old_img_data = new VCComponentData [8];
            VCEditor.s_Mirror.MirrorComponent(old_data);
            for (int i = 0; i < VCEditor.s_Mirror.OutputCnt; ++i)
            {
                old_img_data[i] = VCEditor.s_Mirror.ComponentOutput[i].Copy();
            }

            VCEditor.s_Mirror.MirrorComponent(new_data);
            for (int i = 0; i < VCEditor.s_Mirror.OutputCnt; ++i)
            {
                VCComponentData        image = VCEditor.s_Mirror.ComponentOutput[i];
                List <VCComponentData> edits = VCEditor.s_Scene.m_IsoData.FindComponentsAtPos(old_img_data[i].m_Position, image.m_ComponentId);
                foreach (VCComponentData iter in edits)
                {
                    if (i > 0 && m_Selection.Find(it => it.m_Component.m_Data == iter) != null)
                    {
                        continue;
                    }
                    if (!VCEMath.IsEqualRotation(iter.m_Rotation, old_img_data[i].m_Rotation))
                    {
                        continue;
                    }
                    if (!VCEMath.IsEqualVector(iter.m_Scale, old_img_data[i].m_Scale))
                    {
                        continue;
                    }
                    if (iter.m_Visible != old_img_data[i].m_Visible)
                    {
                        continue;
                    }
                    if (old_img_data[i] is IVCMultiphaseComponentData && iter is IVCMultiphaseComponentData)
                    {
                        if ((old_img_data[i] as IVCMultiphaseComponentData).Phase != (iter as IVCMultiphaseComponentData).Phase)
                        {
                            continue;
                        }
                    }
                    int index = VCEditor.s_Scene.m_IsoData.GetComponentIndex(iter);
                    if (index < 0)
                    {
                        continue;
                    }
                    // Special process for wheels
                    if (i != 0 && image is VCQuadphaseFixedPartData)
                    {
                        (image as VCQuadphaseFixedPartData).m_Phase =
                            ((image as VCQuadphaseFixedPartData).m_Phase & 1) | ((iter as VCQuadphaseFixedPartData).m_Phase & 2);
                    }

                    VCEAlterComponent modify = new VCEAlterComponent(index, iter, image);
                    m_Action.Modifies.Add(modify);
                }
            }
        }
        // No mirror
        else
        {
            int index = VCEditor.s_Scene.m_IsoData.GetComponentIndex(old_data);
            if (index < 0)
            {
                return;
            }
            VCEAlterComponent modify = new VCEAlterComponent(index, old_data, new_data);
            m_Action.Modifies.Add(modify);
        }
        VCEStatusBar.ShowText("Changes applied".ToLocalizationString(), 2);
        m_Action.Do();
    }
Exemplo n.º 21
0
    void OnRotating(Vector3 axis, float angle)
    {
        float hvs = VCEditor.s_Scene.m_Setting.m_VoxelSize * 0.5f;

        VCEditor.s_Mirror.CalcPrepare(hvs * 2);
        foreach (SelectInfo si in m_Selection)
        {
            Vector3 cached_rot = si.m_Component.transform.eulerAngles;
            si.m_Component.transform.eulerAngles = si.m_OldRotation;
            si.m_Component.transform.Rotate(axis, angle, Space.World);
            si.m_DragRotation = si.m_Component.transform.eulerAngles;
            si.m_DragRotation = VCEMath.NormalizeEulerAngle(si.m_DragRotation);
            si.m_NewRotation  = si.m_DragRotation;
            si.m_Component.transform.eulerAngles = cached_rot;

            Vector3 tmp_rot = si.m_Component.m_Data.m_Rotation;
            si.m_Component.m_Data.m_Rotation = si.m_NewRotation;
            si.m_Component.m_Data.Validate();
            if (si.m_Component.m_Data.m_Rotation != si.m_NewRotation)
            {
                si.m_NewRotation = cached_rot;
                si.m_Component.m_Data.m_Rotation = si.m_NewRotation;
                si.m_Component.m_Data.Validate();
            }
            si.m_NewRotation = si.m_Component.transform.eulerAngles = si.m_Component.m_Data.m_Rotation;

            if (m_DataInspector != null)
            {
                m_DataInspector.GetComponent <VCEUIComponentInspector>().Set(si.m_Component.m_Data);
            }

            si.m_Component.m_Data.m_Rotation = tmp_rot;

            // Mirror
            if (VCEditor.s_Mirror.Enabled_Masked)
            {
                Vector3[] old_rots = new Vector3[8];
                VCEditor.s_Mirror.MirrorComponent(si.m_Component.m_Data);
                for (int i = 0; i < VCEditor.s_Mirror.OutputCnt; ++i)
                {
                    old_rots[i] = VCEditor.s_Mirror.ComponentOutput[i].m_Rotation;
                }

                VCComponentData tmpdata = si.m_Component.m_Data.Copy();
                tmpdata.m_Rotation = si.m_NewRotation;
                VCEditor.s_Mirror.MirrorComponent(tmpdata);

                for (int i = 1; i < VCEditor.s_Mirror.OutputCnt; ++i)
                {
                    VCComponentData        image = VCEditor.s_Mirror.ComponentOutput[i];
                    List <VCComponentData> edits = VCEditor.s_Scene.m_IsoData.FindComponentsAtPos(image.m_Position, image.m_ComponentId);
                    foreach (VCComponentData iter in edits)
                    {
                        if (!VCEMath.IsEqualRotation(iter.m_Rotation, old_rots[i]))
                        {
                            continue;
                        }
                        if (iter.m_Scale != image.m_Scale)
                        {
                            continue;
                        }
                        if (iter.m_Visible != image.m_Visible)
                        {
                            continue;
                        }
                        if (image is IVCMultiphaseComponentData && iter is IVCMultiphaseComponentData)
                        {
                            if ((image as IVCMultiphaseComponentData).Phase != (iter as IVCMultiphaseComponentData).Phase)
                            {
                                continue;
                            }
                        }
                        if (m_Selection.Find(it => it.m_Component.m_Data == iter) == null)
                        {
                            iter.m_Entity.transform.eulerAngles = image.m_Rotation;
                        }
                    }
                }
            }
            // End 'mirror'
        }
    }
Exemplo n.º 22
0
    // Moving Gizmo
    void OnMoving(Vector3 offset)
    {
        float hvs = VCEditor.s_Scene.m_Setting.m_VoxelSize * 0.5f;

        VCEditor.s_Mirror.CalcPrepare(hvs * 2);
        foreach (SelectInfo si in m_Selection)
        {
            si.m_DragPosition += offset;
            si.m_NewPosition.x = Mathf.Round(si.m_DragPosition.x / hvs) * hvs;
            si.m_NewPosition.y = Mathf.Round(si.m_DragPosition.y / hvs) * hvs;
            si.m_NewPosition.z = Mathf.Round(si.m_DragPosition.z / hvs) * hvs;
            Vector3 tmp_pos = si.m_Component.m_Data.m_Position;
            si.m_Component.m_Data.m_Position = si.m_NewPosition;
            si.m_Component.m_Data.Validate();
            si.m_NewPosition = si.m_Component.transform.position = si.m_Component.m_Data.m_Position;

            if (m_DataInspector != null)
            {
                m_DataInspector.GetComponent <VCEUIComponentInspector>().Set(si.m_Component.m_Data);
            }

            si.m_Component.m_Data.m_Position = tmp_pos;

            // Mirror
            if (VCEditor.s_Mirror.Enabled_Masked)
            {
                Vector3[] old_poses = new Vector3[8];
                VCEditor.s_Mirror.MirrorComponent(si.m_Component.m_Data);
                for (int i = 0; i < VCEditor.s_Mirror.OutputCnt; ++i)
                {
                    old_poses[i] = VCEditor.s_Mirror.ComponentOutput[i].m_Position;
                }

                VCComponentData tmpdata = si.m_Component.m_Data.Copy();
                tmpdata.m_Position = si.m_NewPosition;
                VCEditor.s_Mirror.MirrorComponent(tmpdata);

                for (int i = 1; i < VCEditor.s_Mirror.OutputCnt; ++i)
                {
                    VCComponentData        image = VCEditor.s_Mirror.ComponentOutput[i];
                    List <VCComponentData> edits = VCEditor.s_Scene.m_IsoData.FindComponentsAtPos(old_poses[i], image.m_ComponentId);
                    foreach (VCComponentData iter in edits)
                    {
                        if (!VCEMath.IsEqualRotation(iter.m_Rotation, image.m_Rotation))
                        {
                            continue;
                        }
                        if (iter.m_Scale != image.m_Scale)
                        {
                            continue;
                        }
                        if (iter.m_Visible != image.m_Visible)
                        {
                            continue;
                        }
                        if (image is IVCMultiphaseComponentData && iter is IVCMultiphaseComponentData)
                        {
                            if ((image as IVCMultiphaseComponentData).Phase != (iter as IVCMultiphaseComponentData).Phase)
                            {
                                continue;
                            }
                        }
                        if (m_Selection.Find(it => it.m_Component.m_Data == iter) == null)
                        {
                            iter.m_Entity.transform.position = image.m_Position;
                        }
                    }
                }
            }
            // End 'mirror'
        }
    }
Exemplo n.º 23
0
    // All Gizmo End
    void OnGizmoEnd()
    {
        if (m_GizmoAction != null)
        {
            VCEditor.s_Mirror.CalcPrepare(VCEditor.s_Scene.m_Setting.m_VoxelSize);
            foreach (SelectInfo si in m_Selection)
            {
                bool modified = false;
                if (!VCEMath.IsEqualVector(si.m_NewPosition, si.m_OldPosition))
                {
                    modified = true;
                }
                if (!VCEMath.IsEqualRotation(si.m_NewRotation, si.m_OldRotation))
                {
                    modified = true;
                }
                if (!VCEMath.IsEqualVector(si.m_NewScale, si.m_OldScale))
                {
                    modified = true;
                }
                if (modified)
                {
                    VCEAlterComponentTransform modify = new VCEAlterComponentTransform(
                        VCEditor.s_Scene.m_IsoData.GetComponentIndex(si.m_Component.m_Data),
                        si.m_OldPosition, si.m_OldRotation, si.m_OldScale,
                        si.m_NewPosition, si.m_NewRotation, si.m_NewScale);

                    m_GizmoAction.Modifies.Add(modify);

                    // Mirror
                    if (VCEditor.s_Mirror.Enabled_Masked)
                    {
                        Vector3[] old_poses  = new Vector3[8];
                        Vector3[] old_rots   = new Vector3[8];
                        Vector3[] old_scales = new Vector3[8];
                        VCEditor.s_Mirror.MirrorComponent(si.m_Component.m_Data);
                        for (int i = 0; i < VCEditor.s_Mirror.OutputCnt; ++i)
                        {
                            old_poses[i]  = VCEditor.s_Mirror.ComponentOutput[i].m_Position;
                            old_rots[i]   = VCEditor.s_Mirror.ComponentOutput[i].m_Rotation;
                            old_scales[i] = VCEditor.s_Mirror.ComponentOutput[i].m_Scale;
                        }

                        VCComponentData tmpdata = si.m_Component.m_Data.Copy();
                        tmpdata.m_Position = si.m_NewPosition;
                        tmpdata.m_Rotation = si.m_NewRotation;
                        tmpdata.m_Scale    = si.m_NewScale;
                        VCEditor.s_Mirror.MirrorComponent(tmpdata);

                        for (int i = 1; i < VCEditor.s_Mirror.OutputCnt; ++i)
                        {
                            VCComponentData image = VCEditor.s_Mirror.ComponentOutput[i];
                            image.Validate();
                            List <VCComponentData> edits = VCEditor.s_Scene.m_IsoData.FindComponentsAtPos(old_poses[i], image.m_ComponentId);
                            foreach (VCComponentData iter in edits)
                            {
                                if (!VCEMath.IsEqualRotation(iter.m_Rotation, old_rots[i]))
                                {
                                    continue;
                                }
                                if (iter.m_Scale != old_scales[i])
                                {
                                    continue;
                                }
                                if (iter.m_Visible != image.m_Visible)
                                {
                                    continue;
                                }
                                if (image is IVCMultiphaseComponentData && iter is IVCMultiphaseComponentData)
                                {
                                    if ((image as IVCMultiphaseComponentData).Phase != (iter as IVCMultiphaseComponentData).Phase)
                                    {
                                        continue;
                                    }
                                }
                                if (m_Selection.Find(it => it.m_Component.m_Data == iter) == null)
                                {
                                    VCEAlterComponentTransform modify_mirror = new VCEAlterComponentTransform(
                                        VCEditor.s_Scene.m_IsoData.GetComponentIndex(iter),
                                        iter.m_Position, iter.m_Rotation, iter.m_Scale,
                                        image.m_Position, image.m_Rotation, image.m_Scale);

                                    m_GizmoAction.Modifies.Add(modify_mirror);
                                }
                            }
                        }
                    }
                    // End 'mirror'
                }
            }
            if (m_GizmoAction.Modifies.Count > 0)
            {
                m_GizmoAction.Do();
                m_GizmoAction = null;
            }
        }
        else
        {
            Debug.LogWarning("Must be some problem here!");
        }
    }
Exemplo n.º 24
0
    private void MirrorComponentOnce(int mirror)
    {
        for (int i = 0; i < OutputCnt; ++i)
        {
            VCComponentData real  = ComponentOutput[i];
            VCComponentData image = ComponentOutput[i].Copy();
            ComponentOutput[i + OutputCnt] = image;
            image.m_Position.x             = ((mirror & 1) > 0)  ?  (2.0f * m_WorldPosX - real.m_Position.x)  :  (real.m_Position.x);
            image.m_Position.y             = ((mirror & 2) > 0)  ?  (2.0f * m_WorldPosY - real.m_Position.y)  :  (real.m_Position.y);
            image.m_Position.z             = ((mirror & 4) > 0)  ?  (2.0f * m_WorldPosZ - real.m_Position.z)  :  (real.m_Position.z);

            bool xsym = true;
            if (image is VCPartData)
            {
                xsym = (VCConfig.s_Parts[image.m_ComponentId].m_Symmetric == 1);
            }
            if (image is VCDecalData)
            {
                xsym = true;
            }

            if (xsym)
            {
                if ((mirror & 1) > 0)
                {
                    //image.m_Rotation.x = image.m_Rotation.x;
                    image.m_Rotation.y = -image.m_Rotation.y;
                    image.m_Rotation.z = -image.m_Rotation.z;
                    if (image is IVCMultiphaseComponentData)
                    {
                        (image as IVCMultiphaseComponentData).InversePhase();
                    }
                }
                if ((mirror & 2) > 0)
                {
                    image.m_Rotation.x = -image.m_Rotation.x;
                    //image.m_Rotation.y = image.m_Rotation.y;
                    image.m_Rotation.z = 180f - image.m_Rotation.z;
                    if (image is IVCMultiphaseComponentData)
                    {
                        (image as IVCMultiphaseComponentData).InversePhase();
                    }
                }
                if ((mirror & 4) > 0)
                {
                    //image.m_Rotation.x = image.m_Rotation.x;
                    image.m_Rotation.y = 180f - image.m_Rotation.y;
                    image.m_Rotation.z = -image.m_Rotation.z;
                    if (image is IVCMultiphaseComponentData)
                    {
                        (image as IVCMultiphaseComponentData).InversePhase();
                    }
                }
            }
            else
            {
                if ((mirror & 1) > 0)
                {
                    if (image is IVCMultiphaseComponentData)
                    {
                        (image as IVCMultiphaseComponentData).InversePhase();
                    }
                }
            }

            image.m_Rotation = VCEMath.NormalizeEulerAngle(image.m_Rotation);
        }
        OutputCnt = OutputCnt << 1;
    }
Exemplo n.º 25
0
    protected override void Do()
    {
        if (VCEditor.SelectedDecalGUID == 0)
        {
            return;
        }
        if (VCEditor.SelectedDecalIndex < 0)
        {
            return;
        }
        if (VCEditor.SelectedDecal == null)
        {
            return;
        }
        m_Action = new VCEAction();

        VCDecalData dcldata = VCComponentData.CreateDecal() as VCDecalData;

        if (dcldata != null)
        {
            dcldata.m_ComponentId = VCDecalData.s_ComponentId;
            dcldata.m_Type        = EVCComponent.cpDecal;
            dcldata.m_Position    = m_DecalInst.transform.localPosition;
            dcldata.m_Rotation    = VCEMath.NormalizeEulerAngle(m_DecalInst.transform.localEulerAngles);
            dcldata.m_Scale       = Vector3.one;
            dcldata.m_Visible     = true;
            dcldata.m_CurrIso     = VCEditor.s_Scene.m_IsoData;
            dcldata.m_Guid        = VCEditor.SelectedDecalGUID;
            dcldata.m_AssetIndex  = VCEditor.SelectedDecalIndex;
            dcldata.m_Size        = m_DecalInst.m_Size;
            dcldata.m_Depth       = m_DecalInst.m_Depth;
            dcldata.m_Mirrored    = m_DecalInst.m_Mirrored;
            dcldata.m_ShaderIndex = m_DecalInst.m_ShaderIndex;
            dcldata.m_Color       = m_DecalInst.m_Color;
            dcldata.Validate();

            ulong olddcl_guid = VCEditor.s_Scene.m_IsoData.DecalGUID(VCEditor.SelectedDecalIndex);
            ulong newdcl_guid = VCEditor.SelectedDecalGUID;
            if (olddcl_guid != newdcl_guid)
            {
                VCEAlterDecalMap modify = new VCEAlterDecalMap(VCEditor.SelectedDecalIndex, olddcl_guid, newdcl_guid);
                modify.Redo();
                m_Action.Modifies.Add(modify);
            }

            VCEditor.s_Mirror.CalcPrepare(VCEditor.s_Scene.m_Setting.m_VoxelSize);
            // Mirror
            if (VCEditor.s_Mirror.Enabled_Masked)
            {
                VCEditor.s_Mirror.MirrorComponent(dcldata);

                for (int i = VCEditor.s_Mirror.OutputCnt - 1; i >= 0; --i)
                {
                    VCComponentData image = VCEditor.s_Mirror.ComponentOutput[i];
                    if (VCEditor.s_Scene.m_IsoData.IsComponentIn(image.m_Position))
                    {
                        VCEAddComponent modify = new VCEAddComponent(VCEditor.s_Scene.m_IsoData.m_Components.Count, image);
                        modify.Redo();
                        m_Action.Modifies.Add(modify);
                    }
                }
            }
            // No mirror
            else
            {
                VCEAddComponent modify = new VCEAddComponent(VCEditor.s_Scene.m_IsoData.m_Components.Count, dcldata);
                modify.Redo();
                m_Action.Modifies.Add(modify);
            }
            m_Action.Register();
        }
        else
        {
            Debug.LogWarning("Decal data create failed");
        }
    }
Exemplo n.º 26
0
    public override void MainMethod()
    {
        if (VCEInput.s_Increase && !VCEInput.s_Shift)
        {
            if (m_Depth < 300)
            {
                m_Depth++;
            }
            m_GUIAlpha = 5;
        }
        else if (VCEInput.s_Decrease && !VCEInput.s_Shift)
        {
            if (m_Depth > 1)
            {
                m_Depth--;
            }
            m_GUIAlpha = 5;
        }
        //
        // Selecting, mouse dragging
        //
        if (m_Selecting)
        {
            if (VCEInput.s_Cancel)
            {
                ExitSelecting();
                return;
            }
            RaycastHit rch;

            // ray cast coord plane
            if (VCEMath.RayCastCoordPlane(VCEInput.s_PickRay, m_Coord, m_PlanePos, out rch))
            {
                m_End.x = Mathf.FloorToInt(rch.point.x);
                m_End.y = Mathf.FloorToInt(rch.point.y);
                m_End.z = Mathf.FloorToInt(rch.point.z);
                switch (m_Coord)
                {
                case ECoordPlane.XY: m_End.z = m_Begin.z + (m_Depth - 1) * m_NormalSign; break;

                case ECoordPlane.XZ: m_End.y = m_Begin.y == 0 && VCEditor.s_Scene.m_IsoData.GetVoxel(VCIsoData.IPosToKey(m_Begin)).Volume < 128 ?
                                               VCEditor.s_Scene.m_Setting.m_EditorSize.y - 1 :
                                               m_Begin.y + (m_Depth - 1) * m_NormalSign;
                    break;

                case ECoordPlane.ZY: m_End.x = m_Begin.x + (m_Depth - 1) * m_NormalSign; break;

                default: ExitSelecting(); return;
                }
            }
            else
            {
                ExitSelecting();
                return;
            }
            m_Iso.ClampPointI(m_Begin);
            m_Iso.ClampPointI(m_End);

            // Submit this selecting action !
            if (Input.GetMouseButtonUp(0) && m_Selecting)
            {
                Submit();
                m_Selecting  = false;
                m_NeedUpdate = true;
            }
        }         // End selecting

        //
        // Free mouse, prepare to select
        //
        else
        {
            // Mouse not on GUI
            if (!VCEInput.s_MouseOnUI)
            {
                // Click left mouse button
                if (Input.GetMouseButtonDown(0))
                {
                    // has draw target
                    if (m_Parent.m_Target.snapto != null && m_Parent.m_Target.cursor != null)
                    {
                        VCEMath.DrawTarget dtar = m_Parent.m_Target;
                        // snapto has voxel
                        if (m_Iso.GetVoxel(VCIsoData.IPosToKey(dtar.snapto)).Volume > 0)
                        {
                            m_Begin.x = dtar.snapto.x;
                            m_Begin.y = dtar.snapto.y;
                            m_Begin.z = dtar.snapto.z;
                        }
                        // snapto don't has voxel
                        else
                        {
                            m_Begin.x       = dtar.cursor.x;
                            m_Begin.y       = dtar.cursor.y;
                            m_Begin.z       = dtar.cursor.z;
                            dtar.rch.normal = -dtar.rch.normal;
                        }

                        // Assgin end
                        m_End.x = m_Begin.x;
                        m_End.y = m_Begin.y;
                        m_End.z = m_Begin.z;
                        // Assgin coord and position
                        // zy plane
                        if (Mathf.Abs(dtar.rch.normal.x) > 0.9f)
                        {
                            m_Coord      = ECoordPlane.ZY;
                            m_PlanePos   = dtar.rch.point.x;
                            m_Selecting  = true;
                            m_NormalSign = -Mathf.RoundToInt(Mathf.Sign(dtar.rch.normal.x));
                        }
                        // xz plane
                        else if (Mathf.Abs(dtar.rch.normal.y) > 0.9f)
                        {
                            m_Coord      = ECoordPlane.XZ;
                            m_PlanePos   = dtar.rch.point.y;
                            m_Selecting  = true;
                            m_NormalSign = -Mathf.RoundToInt(Mathf.Sign(dtar.rch.normal.y));
                        }
                        // xy plane
                        else if (Mathf.Abs(dtar.rch.normal.z) > 0.9f)
                        {
                            m_Coord      = ECoordPlane.XY;
                            m_PlanePos   = dtar.rch.point.z;
                            m_Selecting  = true;
                            m_NormalSign = -Mathf.RoundToInt(Mathf.Sign(dtar.rch.normal.z));
                        }
                        // it's impossible !!!
                        else
                        {
                            Debug.LogError("It's impossible !!");
                            ExitSelecting();
                        }
                    }
                    // Don't have draw target
                    else
                    {
                        // Select
                        if (!VCEInput.s_Shift && !VCEInput.s_Alt && !VCEInput.s_Control)
                        {
                            m_Selection.Clear();
                        }
                        m_NeedUpdate = true;
                    }
                }
            }

            if (m_MaterialSelectChange)
            {
                Submit();
                m_Selecting  = false;
                m_NeedUpdate = true;
            }
        }         // End free mouse
    }
Exemplo n.º 27
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);
        }

        Vector3 pa = Vector3.zero;
        Vector3 pb = Vector3.zero;
        Vector3 pc = Vector3.zero;

        switch (m_Direction)
        {
        default:
        case 0: pa = new Vector3(Min.x, Min.y, Min.z - 0.5f); pb = new Vector3(Max.x + 1, Max.y + 1.5f, Max.z + 1); pc = new Vector3(Max.x + 1, Min.y, Min.z - 0.5f); break;

        case 1: pa = new Vector3(Max.x + 1, Max.y + 1, Max.z + 1.5f); pb = new Vector3(Min.x, Min.y - 0.5f, Min.z); pc = new Vector3(Max.x + 1, Min.y - 0.5f, Min.z); break;

        case 2: pa = new Vector3(Min.x, Max.y + 1.5f, Min.z); pb = new Vector3(Max.x + 1, Min.y, Max.z + 1.5f); pc = new Vector3(Max.x + 1, Max.y + 1.5f, Min.z); break;

        case 3: pa = new Vector3(Max.x + 1, Min.y - 0.5f, Max.z + 1); pb = new Vector3(Min.x, Max.y + 1, Min.z - 0.5f); pc = new Vector3(Max.x + 1, Max.y + 1, Min.z - 0.5f); break;

        case 4: pa = new Vector3(Min.x - 0.5f, Min.y, Min.z); pb = new Vector3(Max.x + 1, Max.y + 1, Max.z + 1.5f); pc = new Vector3(Min.x - 0.5f, Max.y + 1, Min.z); break;

        case 5: pa = new Vector3(Max.x + 1.5f, Max.y + 1, Max.z + 1); pb = new Vector3(Min.x, Min.y, Min.z - 0.5f); pc = new Vector3(Min.x, Max.y + 1, Min.z - 0.5f); break;

        case 6: pa = new Vector3(Max.x + 1, Min.y, Min.z - 0.5f); pb = new Vector3(Min.x - 0.5f, Max.y + 1, Max.z + 1); pc = new Vector3(Max.x + 1, Max.y + 1, Min.z - 0.5f); break;

        case 7: pa = new Vector3(Min.x, Max.y + 1, Max.z + 1.5f); pb = new Vector3(Max.x + 1.5f, Min.y, Min.z); pc = new Vector3(Max.x + 1.5f, Max.y + 1, Min.z); break;

        case 8:  pa = new Vector3(Min.x, Min.y - 0.5f, Min.z); pb = new Vector3(Max.x + 1.5f, Max.y + 1, Max.z + 1); pc = new Vector3(Min.x, Min.y - 0.5f, Max.z + 1); break;

        case 9:  pa = new Vector3(Max.x + 1, Max.y + 1.5f, Max.z + 1); pb = new Vector3(Min.x - 0.5f, Min.y, Min.z); pc = new Vector3(Min.x - 0.5f, Min.y, Max.z + 1); break;

        case 10: pa = new Vector3(Max.x + 1.5f, Min.y, Min.z); pb = new Vector3(Min.x, Max.y + 1.5f, Max.z + 1); pc = new Vector3(Max.x + 1.5f, Min.y, Max.z + 1); break;

        case 11: pa = new Vector3(Min.x - 0.5f, Max.y + 1, Max.z + 1); pb = new Vector3(Max.x + 1, Min.y - 0.5f, Min.z); pc = new Vector3(Max.x + 1, Min.y - 0.5f, Max.z + 1); break;
        }

        //Vector3 offset = m_Offset * Vector3.up;
        //Vector3 offset2 = (m_Offset-m_Thickness) * Vector3.up;
        Plane pl = new Plane(pa, pb, pc);

        //Plane pl2 = new Plane (pa+offset2, pc+offset2, pb+offset2);

        VCEditor.s_Mirror.CalcPrepare(VCEditor.s_Scene.m_Setting.m_VoxelSize);
        IntVector3 min = Min;
        IntVector3 max = Max;

        for (int x = min.x; x <= max.x; ++x)
        {
            for (int y = min.y; y <= max.y; ++y)
            {
                for (int z = min.z; z <= max.z; ++z)
                {
                    float volume = VCEMath.DetermineVolume(x, y, z, pl);
                    //float volume2 = VCEMath.DetermineVolume(x,y,z,pl2);
                    int vol = Mathf.RoundToInt(volume);
                    if (vol == 0)
                    {
                        continue;
                    }
                    // Mirror
                    if (VCEditor.s_Mirror.Enabled_Masked)
                    {
                        VCEditor.s_Mirror.MirrorVoxel(new IntVector3(x, y, z));
                        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((byte)vol, (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(new IntVector3(x, y, z));
                        VCVoxel old_voxel = VCEditor.s_Scene.m_IsoData.GetVoxel(voxel_pos);
                        VCVoxel new_voxel = new VCVoxel((byte)vol, (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();
        }
        ResetDrawing();
    }
Exemplo n.º 28
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);
        }
    }
Exemplo n.º 29
0
    void Update()
    {
        // Save recent vars
        s_RecentRadius   = m_Radius;
        s_RecentHardness = m_Hardness;
        s_RecentStrength = m_Strength;

        // Prepare collider
        if (!VCEditor.s_Scene.m_MeshComputer.Computing)
        {
            if (m_MeshMgr.m_ColliderDirty)
            {
                m_MeshMgr.PrepareMeshColliders();
            }
        }
        if (m_MeshMgr.m_ColliderDirty)
        {
            return;
        }

        // Color ( target & display )
        m_TargetColor = m_Eraser ? VCIsoData.BLANK_COLOR : VCEditor.SelectedColor;
        m_UIColor     = m_TargetColor;
        m_UIColor.a   = 1;

        // Update mesh color
        foreach (MeshFilter mf in m_NeedUpdateMfs)
        {
            m_MeshMgr.UpdateMeshColor(mf);
        }
        m_NeedUpdateMfs.Clear();

        // Drawing
        if (m_Drawing)
        {
            if (VCEInput.s_Cancel)
            {
                m_Drawing = false;
                if (m_Action != null)
                {
                    m_Action.Undo();
                    m_Action = null;
                }
                else
                {
                    Debug.LogError("There must be some problem");
                }
            }
            else
            {
                if (Input.GetMouseButtonUp(0))
                {
                    m_Drawing = false;
                    if (m_Action != null)
                    {
                        VCEUpdateColorSign sign_f = new VCEUpdateColorSign(true, false);
                        m_Action.Modifies.Add(sign_f);
                        if (m_Action.Modifies.Count > 2)
                        {
                            m_Action.Do();
                        }
                        m_Action = null;
                    }
                    else
                    {
                        Debug.LogError("There must be some problem");
                    }
                }
                else
                {
                    // Mouse is pressing
                    // During drawing: From 2nd frame since mouse down

                    // 1. Test hitpoint now
                    RaycastHit rch;
                    Vector3    hit;
                    if (VCEMath.RayCastMesh(VCEInput.s_PickRay, out rch))
                    {
                        hit       = rch.point;
                        m_simDist = rch.distance;
                    }
                    else
                    {
                        hit = VCEInput.s_PickRay.GetPoint(m_simDist);
                    }

                    // 2. Step by step ray cast
                    Vector3 move_vec = hit - m_lastHit;
                    if (move_vec.magnitude > m_simStep)
                    {
                        float ustep = m_simStep / move_vec.magnitude;

                        // traverse all the interpolation points
                        for (float t = ustep; t < 0.999f + ustep; t += ustep)
                        {
                            t = Mathf.Clamp01(t);
                            Vector3 inter_point = m_lastHit + t * move_vec;
                            Ray     test_ray    = new Ray(VCEInput.s_PickRay.origin, (inter_point - VCEInput.s_PickRay.origin).normalized);
                            if (VCEMath.RayCastMesh(test_ray, out rch))
                            {
                                m_simDist = rch.distance;
                                if ((rch.point - m_lastDraw).magnitude > m_drawStep)
                                {
                                    PaintPosition(rch.point, rch.normal);
                                    m_lastDraw = rch.point;
                                    Debug.DrawRay(test_ray.origin, inter_point - VCEInput.s_PickRay.origin, m_UIColor, 10.0f);
                                }
                                else
                                {
                                    Debug.DrawRay(test_ray.origin, inter_point - VCEInput.s_PickRay.origin, new Color(m_UIColor.r, m_UIColor.g, m_UIColor.b, 0.2f), 10.0f);
                                }
                            }
                            else
                            {
                                Debug.DrawRay(test_ray.origin, inter_point - VCEInput.s_PickRay.origin, new Color(m_UIColor.r, m_UIColor.g, m_UIColor.b, 0.1f), 10.0f);
                            }
                        }
                        // 3. Update last hitpoint
                        m_lastHit = hit;
                    }
                }
            }
        }
        else
        {
            if (VCEInput.s_Cancel)
            {
                Cancel();
            }
            else
            {
                if (Input.GetMouseButtonDown(0) && !VCEInput.s_MouseOnUI)
                {
                    m_Drawing = true;
                    if (m_Action != null)
                    {
                        Debug.LogError("There must be some problem");
                        m_Action = null;
                    }
                    m_Action = new VCEAction();
                    VCEUpdateColorSign sign_b = new VCEUpdateColorSign(false, true);
                    m_Action.Modifies.Add(sign_b);

                    // draw once

                    // Init continous drawing vars
                    m_lastHit  = Vector3.zero;
                    m_lastDraw = Vector3.one * (-100);
                    m_simStep  = Mathf.Clamp(m_Radius * 0.07f, 0.2f, 100.0f) * VCEditor.s_Scene.m_Setting.m_VoxelSize;
                    m_drawStep = Mathf.Clamp(m_Radius * 0.5f, 0.2f, 100.0f) * VCEditor.s_Scene.m_Setting.m_VoxelSize;
                    m_simDist  = VCEditor.s_Scene.m_Setting.EditorWorldSize.magnitude * 0.2f;

                    RaycastHit rch;
                    // cast
                    if (VCEMath.RayCastMesh(VCEInput.s_PickRay, out rch))
                    {
                        PaintPosition(rch.point, rch.normal);
                        m_lastHit  = rch.point;
                        m_lastDraw = rch.point;
                        m_simDist  = rch.distance;
                    }
                    // no cast
                    else
                    {
                        m_lastHit = VCEInput.s_PickRay.GetPoint(m_simDist);
                    }
                }
            }
        }
    }