예제 #1
0
    /// <summary>
    /// Update is called every frame, if the MonoBehaviour is enabled.
    /// </summary>
    public void Update()
    {
        if (!Input.GetKey(KeyCode.LeftControl) && !Input.GetKey(KeyCode.RightControl))
        {
            threadStart = null;
        }
        if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
        {
            //we are using the scalpel
            return;
        }

        if (Input.GetMouseButtonDown(0) && (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)))
        {
            if (threadStart == null)
            {
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                threadStart = _skinMesh.GetClosestSkinVertexToLineSgement(ray.origin, ray.GetPoint(10f), _skin.snapDistance);
            }
            else
            {
                Ray        ray        = Camera.main.ScreenPointToRay(Input.mousePosition);
                SkinVertex skinVertex = _skinMesh.GetClosestSkinVertexToLineSgement(ray.origin, ray.GetPoint(10f), _skin.snapDistance);
                if (skinVertex != null)
                {
                    _skinMesh.AddThread(threadStart.vertexIndex, skinVertex.vertexIndex);
                    threadStart = skinVertex;
                }
            }
        }
    }
예제 #2
0
    /// <summary>
    /// Update is called every frame, if the MonoBehaviour is enabled.
    /// </summary>
    public void Update()
    {
        if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
        {
            //we are using the needle
            return;
        }

        if (Input.GetMouseButton(0) && (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)))
        {
            if (cutStart == null)
            {
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                cutStart = _skinMesh.GetClosestSkinVertexToLineSgement(ray.origin, ray.GetPoint(10f), _skin.snapDistance);
            }
            else
            {
                Ray        ray    = Camera.main.ScreenPointToRay(Input.mousePosition);
                SkinVertex cutEnd = _skinMesh.GetClosestSkinVertexToLineSgement(ray.origin, ray.GetPoint(10f), _skin.snapDistance);
                _skinMesh.Cut(cutStart, cutEnd, _skin.snapDistance, cutDepth);
                cutStart = cutEnd;
            }
        }
        else
        {
            _cutStart = null;
        }
    }
예제 #3
0
    /// <summary>
    /// Update is called every frame, if the MonoBehaviour is enabled.
    /// </summary>
    public void Update()
    {
        if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
        {
            //we are using the needle
            return;
        }
        if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
        {
            //we are using the scalpel
            return;
        }
        if (Input.GetMouseButton(0))
        {
            if (dragSkinVertex == null)
            {
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                dragSkinVertex = _skinMesh.GetClosestSkinVertexToLineSgement(ray.origin, ray.GetPoint(10f), _skin.snapDistance);
                if (dragSkinVertex != null)
                {
                    originalVertexHeight = dragSkinVertex.currentPosition.y;
                }
                _draggingHeight = 0f;
            }
            else
            {
                if (_draggingHeight < maxHeight)
                {
                    _draggingHeight = Mathf.Min(maxHeight, _draggingHeight + Time.deltaTime * maxHeight); //1 second to get to the max height
                }
                Vector3 newPosition = Camera.main.ScreenToWorldPoint(
                    new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.y - (originalVertexHeight + _draggingHeight)));

                Vector3 skinVertexForce           = dragSkinVertex.resultingForce;
                Vector3 skinVertexForceNormalized = skinVertexForce.normalized;
                Vector3 newForce = newPosition - dragSkinVertex.currentPosition;

                //The size of the projection of the new force on the normalized skin vertex force.
                float newForceProjectedMagnitude = Vector3.Dot(newForce, skinVertexForceNormalized);

                if (newForceProjectedMagnitude < 0.0f)
                {
                    float multiplier = Mathf.Clamp01(0.5f - 0.33f * Mathf.Atan(skinVertexForce.magnitude - maximumPullForce));
                    newPosition = dragSkinVertex.currentPosition + newForce * multiplier;
                }
                dragSkinVertex.currentPosition = newPosition;
            }
        }
        else
        {
            _dragSkinVertex = null;
        }
    }