예제 #1
0
    /// <summary>
    /// Updates the model for this thread.
    /// </summary>
    public void UpdateModel()
    {
        if (Model == null && threadModelPrefab != null)
        {
            Model = Object.Instantiate(threadModelPrefab) as GameObject;
            Debug.Log("Thread model made1");
            if (Model == null)
            {
                return;
            }

            Model.transform.parent = threadModelsParentTransform;
        }

        if (Model == null)
        {
            return;
        }

        Vector3 sv0Position = _skinMesh.GetSkinVertex(vertex0Index).currentPosition;
        Vector3 sv1Position = _skinMesh.GetSkinVertex(vertex1Index).currentPosition;

        Model.transform.position = (sv0Position + sv1Position) / 2.0f;

        Vector3 localScale = Model.transform.localScale;

        localScale.y = (sv0Position - sv1Position).magnitude / 2.0f;
        Model.transform.localScale = localScale;

        Model.transform.up = Model.transform.position - sv0Position;
    }
예제 #2
0
    /// <summary>
    /// Calculates the resulting force on this skin vertex based on
    /// the gravity and the spring forces of all edges starting in this skin vertex.
    /// This value will be cached and used in the associated 'ApplyAcceleration()' method.
    /// </summary>
    public void CalculateResultingForce()
    {
        _resultingForce = Mathf.Atan(currentPosition.y) * Physics.gravity * 0.05f * _skinMesh.gravityMultiplier + addedForces;

        Vector3 skinEdgesResultingForce = Vector3.zero;

        foreach (SkinEdge skinEdge in edges)
        {
            skinEdge.ShuffleVertexIndices(vertexIndex);
            SkinVertex otherSkinVertex = _skinMesh.GetSkinVertex(skinEdge.vertex1Index);
            skinEdgesResultingForce += skinEdge.cachedSpringForce * (otherSkinVertex.currentPosition - currentPosition).normalized;
        }

        if (threads.Count == 0)
        {
            _resultingForce += skinEdgesResultingForce;
        }
        else
        {
            Vector3 threadsResultingForce = Vector3.zero;
            foreach (Thread thread in threads)
            {
                thread.ShuffleVertexIndices(vertexIndex);
                SkinVertex otherSkinVertex = _skinMesh.GetSkinVertex(thread.vertex1Index);
                threadsResultingForce += thread.cachedSpringForce * (otherSkinVertex.currentPosition - currentPosition).normalized;
            }

            _resultingForce += skinEdgesResultingForce + threadsResultingForce;
        }
    }
예제 #3
0
    /// <summary>
    /// Recalculates the area of this skin triangle and caches it.
    /// </summary>
    /// <returns>The area of this skin triangle.</returns>
    public float UpdateCachedArea()
    {
        Vector3 v0 = _skinMesh.GetSkinVertex(vertex0Index).currentPosition;
        Vector3 v1 = _skinMesh.GetSkinVertex(vertex1Index).currentPosition;
        Vector3 v2 = _skinMesh.GetSkinVertex(vertex2Index).currentPosition;

        Vector3 v2P = MathHelper.GetProjectedPointOnLine(v0, v1, v2);

        cachedArea = (v0 - v1).magnitude * (v2 - v2P).magnitude * 0.5f;

        return(cachedArea);
    }