Exemplo n.º 1
0
 public LinkedVertex(apPhysicsVertParam.LinkedVertex srcLinkedVertex)
 {
     _vertex        = null;
     _vertIndex     = srcLinkedVertex._vertex._index;
     _modVertWeight = null;
     _distWeight    = srcLinkedVertex._distWeight;
 }
Exemplo n.º 2
0
        public void Bake(apPhysicsVertParam srcVertParam)
        {
            _isConstraint = srcVertParam._isConstraint;
            _isMain       = srcVertParam._isMain;

            _linkedVertices.Clear();
            for (int i = 0; i < srcVertParam._linkedVertices.Count; i++)
            {
                apPhysicsVertParam.LinkedVertex srcLinkedVert = srcVertParam._linkedVertices[i];
                _linkedVertices.Add(new OptLinkedVertex(srcLinkedVert));                //<<Add + Bake
            }

            _viscosityGroupID = srcVertParam._viscosityGroupID;
        }
Exemplo n.º 3
0
            public OptLinkedVertex(apPhysicsVertParam.LinkedVertex srcLinkedVertex)
            {
                //_vertex = vertex;
                _vertex       = null;
                _vertUniqueID = srcLinkedVertex._vertUniqueID;
                _vertIndex    = srcLinkedVertex._vertex._index;

                _modVertWeight = null;

                _deltaPosLocal = srcLinkedVertex._deltaPosLocalLinkToTarget;
                _distLocal     = srcLinkedVertex._distLocal;
                _distWeight    = srcLinkedVertex._distWeight;

                _level = srcLinkedVertex._level;
            }
        public void RefreshLinkedVertex()
        {
            if (_isPhysics)
            {
                _physicParam.RefreshLinkedVertex();

                //영역을 체크하자
                //일단 최소 거리와 평균 거리를 구한다.
                float minDist = 0.0f;
                //float avgDist = 0.0f;
                int nDist = 0;

                for (int i = 0; i < _physicParam._linkedVertices.Count; i++)
                {
                    apPhysicsVertParam.LinkedVertex linkVert = _physicParam._linkedVertices[i];
                    float distW = (linkVert._modVertWeight._pos_World_NoMod - _pos_World_NoMod).magnitude;
                    if (nDist == 0 || distW < minDist)
                    {
                        minDist = distW;
                    }

                    //avgDist += distW;
                    nDist++;
                }
                //if(nDist > 0)
                //{
                //	avgDist /= nDist;
                //}

                _deltaPosRadius_Free = minDist * 0.5f;
                //_deltaPosRadius_Max = avgDist * 0.5f;
                _deltaPosRadius_Max = minDist;
                if (_deltaPosRadius_Max < _deltaPosRadius_Free)
                {
                    _deltaPosRadius_Free = _deltaPosRadius_Max * 0.5f;
                }
            }
        }
Exemplo n.º 5
0
        public void Bake(apModifiedVertexWeight srcModVertWeight)
        {
            _isEnabled = srcModVertWeight._isEnabled;
            _weight    = srcModVertWeight._weight;

            _pos_World_NoMod = srcModVertWeight._pos_World_NoMod;


            //PhysicsParam도 Bake
            apPhysicsVertParam srcVertParam = srcModVertWeight._physicParam;

            _isConstraint = srcVertParam._isConstraint;
            _isMain       = srcVertParam._isMain;

            _linkedVertices.Clear();
            for (int i = 0; i < srcVertParam._linkedVertices.Count; i++)
            {
                apPhysicsVertParam.LinkedVertex srcLinkedVert = srcVertParam._linkedVertices[i];
                _linkedVertices.Add(new LinkedVertex(srcLinkedVert));                //<<Add + Bake
            }

            _viscosityGroupID = srcVertParam._viscosityGroupID;
        }
        // Functions
        //------------------------------------------------------
        /// <summary>
        /// ModMesh, RenderVert 변경 사항을 갱신하고,
        /// 데이터 타입에 따라서 Refresh를 한다.
        /// </summary>
        /// <param name="modifiedMesh"></param>
        public void RefreshModMeshAndWeights(apModifiedMesh modifiedMesh)
        {
            if (modifiedMesh != null)
            {
                if (_modifiedMesh != modifiedMesh ||
                    _renderVertex == null ||
                    _renderUnit != modifiedMesh._renderUnit)
                {
                    _modifiedMesh = modifiedMesh;
                    _renderUnit   = modifiedMesh._renderUnit;
                    if (_modifiedMesh != null && modifiedMesh._renderUnit != null && _vertex != null)
                    {
                        _renderVertex = modifiedMesh._renderUnit._renderVerts.Find(delegate(apRenderVertex a)
                        {
                            return(a._vertex == _vertex);
                        });
                    }

                    if (_isPhysics)
                    {
                        _physicParam.Link(modifiedMesh, this);
                    }
                }
            }

            _calculatedDeltaPos = Vector2.zero;

            //Debug.Log("Refresh Physic Param");
            if (_isPhysics)
            {
                //Mod가 포함되지 않은 "초기 위치"
                if (_renderVertex != null)
                {
                    _pos_World_NoMod = _renderVertex._pos_World_NoMod;

                    _pos_Real    = Vector2.zero;
                    _pos_1F      = Vector2.zero;
                    _pos_Predict = Vector2.zero;
                    _tDelta_1F   = -1.0f;

                    //for (int i = 0; i < _pos_World_Records.Length; i++)
                    //{
                    //	_pos_World_Records[i] = Vector2.zero;
                    //	_velocity_Records[i] = Vector2.zero;
                    //}

                    //for (int i = 0; i < _tDelta_Records.Length; i++)
                    //{
                    //	_tDelta_Records[i] = 0.0f;
                    //}

                    _velocity_1F   = Vector2.zero;
                    _velocity_Next = Vector2.zero;
                    _velocity_Real = Vector2.zero;

                    //_acc_Cur = Vector2.zero;
                    _acc_Ex = Vector2.zero;


                    _F_inertia_Prev      = Vector2.zero;
                    _F_inertia_RecordMax = Vector2.zero;
                    _isUsePrevInertia    = false;
                    _tReduceInertia      = 0.0f;
                }

                //이제 전체적으로 Enabled를 기준으로 Constraint를 지정해보자
                //Constraint 조건
                //- 자신은 Enabled = false
                //- 1-Level 중에 Enabled = true인게 1개 이상 있다.

                if (_isEnabled)
                {
                    _physicParam._isConstraint = false;
                }
                else
                {
                    //1-Level 중에서 하나라도 유효한 Vert가 연결되어 있으면
                    //Constraint이다.
                    bool isAnyEnabledLinkedVert = false;
                    apPhysicsVertParam.LinkedVertex linkedVert = null;
                    for (int i = 0; i < _physicParam._linkedVertices.Count; i++)
                    {
                        linkedVert = _physicParam._linkedVertices[i];
                        if (linkedVert._level != 1)
                        {
                            continue;
                        }

                        if (linkedVert._modVertWeight._isEnabled)
                        {
                            isAnyEnabledLinkedVert = true;
                            break;
                        }
                    }

                    if (isAnyEnabledLinkedVert)
                    {
                        _physicParam._isConstraint = true;
                    }
                    else
                    {
                        _physicParam._isConstraint = false;                        //주변에 물리가 작동하는 Vert가 아예 없군염
                    }
                }
            }
        }