Пример #1
0
        //개선된 버전 19.5.23
        public void Link(apOptModifiedMesh_Physics modMeshPhysics,
                         apOptModifiedMeshSet modMeshSet,
                         apOptTransform optTransform,
                         apOptRenderVertex vertex)
        {
            //>>19.5.23 : 삭제 (불필요)
            //_modifiedMesh = modifiedMesh;
            //_mesh = mesh;
            _vertex       = vertex;
            _optTransform = optTransform;

            if (_linkedVertices == null)
            {
                _linkedVertices = new List <LinkedVertex>();
            }


            apOptMesh mesh = modMeshSet._targetMesh;

            //이미 Bake 되었으므로 바로 Link하면 된다.
            for (int i = 0; i < _linkedVertices.Count; i++)
            {
                LinkedVertex               linkedVert = _linkedVertices[i];
                apOptRenderVertex          renderVert = mesh.RenderVertices[linkedVert._vertIndex];
                apOptModifiedPhysicsVertex linkVert   = modMeshSet.SubModMesh_Physics._vertWeights[linkedVert._vertIndex];
                linkedVert.Link(renderVert, linkVert);
            }

            DampPhysicVertex();
        }
Пример #2
0
 public LinkedVertex(apPhysicsVertParam.LinkedVertex srcLinkedVertex)
 {
     _vertex        = null;
     _vertIndex     = srcLinkedVertex._vertex._index;
     _modVertWeight = null;
     _distWeight    = srcLinkedVertex._distWeight;
 }
        public void Link(apOptModifiedMesh modifiedMesh, apOptTransform optTransform, apOptMesh mesh, apOptRenderVertex vertex)
        {
            _modifiedMesh = modifiedMesh;
            _mesh         = mesh;
            _vertex       = vertex;
            _optTransform = optTransform;

            if (_physicParam != null)
            {
                _physicParam.Link(modifiedMesh, this);
            }

            DampPhysicVertex();
        }
Пример #4
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;
            }
Пример #5
0
        /// <summary>
        /// Linked Vertex의 객체를 Link한다.
        /// </summary>
        /// <param name="parentModMesh"></param>
        public void Link(apOptModifiedMesh parentModMesh, apOptModifiedVertexWeight parentModVertWeight)
        {
            _parentModMesh = parentModMesh;
            //_parentModVertWeight = parentModVertWeight;

            if (_linkedVertices == null)
            {
                _linkedVertices = new List <OptLinkedVertex>();
            }


            apOptMesh mesh = parentModMesh._targetMesh;

            //이미 Bake 되었으므로 바로 Link하면 된다.
            for (int i = 0; i < _linkedVertices.Count; i++)
            {
                OptLinkedVertex           linkedVert     = _linkedVertices[i];
                apOptRenderVertex         renderVert     = mesh.RenderVertices[linkedVert._vertIndex];
                apOptModifiedVertexWeight linkVertWeight = _parentModMesh._vertWeights[linkedVert._vertIndex];
                linkedVert.Link(renderVert, linkVertWeight);
            }
        }
Пример #6
0
 public void Link(apOptRenderVertex linkedVertex, apOptModifiedVertexWeight linkedModVertWeight)
 {
     _vertex        = linkedVertex;
     _modVertWeight = linkedModVertWeight;
 }
Пример #7
0
        public void UpdateCalculate(bool isRigging, bool isVertexLocal, bool isVertexWorld, bool isVisible)
        {
            if (_isVisible != isVisible)
            {
                if (isVisible)
                {
                    Show();
                }
                else
                {
                    Hide();                    //<안보인닷!
                }
            }

            //안보이는건 업데이트하지 말자
            if (isVisible)
            {
                apOptRenderVertex rVert = null;

                //Compute Shader를 써보자
                if (apComputeShader.I.IsComputable_Opt && _portrait._isGPUAccel)
                {
                    for (int i = 0; i < _nVert; i++)
                    {
                        rVert = _renderVerts[i];
                        rVert.ReadyToCalculate();

                        if (isRigging)
                        {
                            rVert.SetRigging_0_LocalPosWeight(_parentTransform.CalculatedStack.GetVertexRigging(i),
                                                              _parentTransform.CalculatedStack.GetRiggingWeight());
                        }

                        if (isVertexLocal)
                        {
                            rVert.SetMatrix_2_Calculate_VertLocal(_parentTransform.CalculatedStack.GetVertexLocalPos(i));
                        }

                        //rVert.SetMatrix_3_Transform_Mesh(_parentTransform._matrix_TF_Cal_ToWorld);
                        rVert.SetMatrix_3_Transform_Mesh(_parentTransform._matrix_TFResult_World.MtrxToSpace);

                        if (isVertexWorld)
                        {
                            rVert.SetMatrix_4_Calculate_VertWorld(_parentTransform.CalculatedStack.GetVertexWorldPos(i));
                        }
                    }

                    apComputeShader.I.Compute_Opt(_renderVerts, _matrix_Vert2Mesh, _matrix_Vert2Mesh_Inverse, _parentTransform._matrix_TFResult_World.MtrxToSpace, ref _vertPositions_Updated);
                }
                else
                {
                    for (int i = 0; i < _nVert; i++)
                    {
#if UNITY_EDITOR
                        Profiler.BeginSample("Opt Mesh - Update calculate Render Vertices");
#endif
                        rVert = _renderVerts[i];

#if UNITY_EDITOR
                        Profiler.BeginSample("Opt Mesh - Set Matrix");
#endif
                        //rVert.SetMatrix_1_Static_Vert2Mesh(...)<<이건 Bake때 넣어줍니다.

                        //리깅 추가
                        if (isRigging)
                        {
                            rVert.SetRigging_0_LocalPosWeight(_parentTransform.CalculatedStack.GetVertexRigging(i),
                                                              _parentTransform.CalculatedStack.GetRiggingWeight());
                        }

                        if (isVertexLocal)
                        {
                            rVert.SetMatrix_2_Calculate_VertLocal(_parentTransform.CalculatedStack.GetVertexLocalPos(i));
                        }

                        //rVert.SetMatrix_3_Transform_Mesh(_parentTransform._matrix_TF_Cal_ToWorld);
                        rVert.SetMatrix_3_Transform_Mesh(_parentTransform._matrix_TFResult_World.MtrxToSpace);

                        if (isVertexWorld)
                        {
                            rVert.SetMatrix_4_Calculate_VertWorld(_parentTransform.CalculatedStack.GetVertexWorldPos(i));
                        }

#if UNITY_EDITOR
                        Profiler.EndSample();
#endif

#if UNITY_EDITOR
                        Profiler.BeginSample("Opt Mesh - Matrix Calculate");
#endif

                        rVert.Calculate();

                        //업데이트 데이터를 넣어준다.
                        _vertPositions_Updated[i] = rVert._vertPos3_LocalUpdated;

#if UNITY_EDITOR
                        Profiler.EndSample();
#endif

#if UNITY_EDITOR
                        Profiler.EndSample();
#endif
                    }
                }
            }


            _material.SetColor("_Color", _multiplyColor * _parentTransform._meshColor2X);

#if UNITY_EDITOR
            Profiler.BeginSample("Opt Mesh - Refresh Mesh");
#endif

            //if (!_isMaskParent && !_isMaskChild)
            if (!_isMaskChild)
            {
                //Mask와 관련이 없는 경우만 갱신해준다.
                //메시 갱신
                RefreshMesh();
            }

#if UNITY_EDITOR
            Profiler.EndSample();
#endif
        }
Пример #8
0
        // Bake
        //------------------------------------------------
        public void BakeMesh(Vector3[] vertPositions,
                             Vector2[] vertUVs,
                             int[] vertUniqueIDs,
                             int[] vertTris,
                             Vector2 pivotPos,
                             apOptTransform parentTransform,
                             Texture2D texture,
                             apPortrait.SHADER_TYPE shaderType,
                             Shader shaderNormal, Shader shaderClipping
                             )
        {
            _parentTransform = parentTransform;

            _vertPositions = vertPositions;
            _vertUVs       = vertUVs;
            _vertUniqueIDs = vertUniqueIDs;
            _vertTris      = vertTris;
            _texture       = texture;

            _pivotPos = pivotPos;
            _nVert    = _vertPositions.Length;


            transform.localPosition += new Vector3(-_pivotPos.x, -_pivotPos.y, 0.0f);

            _matrix_Vert2Mesh         = apMatrix3x3.TRS(new Vector2(-_pivotPos.x, -_pivotPos.y), 0, Vector2.one);
            _matrix_Vert2Mesh_Inverse = _matrix_Vert2Mesh.inverse;

            _shaderType     = shaderType;
            _shaderNormal   = shaderNormal;
            _shaderClipping = shaderClipping;

            if (_shaderNormal == null)
            {
                Debug.LogError("Shader Normal is Null");
            }
            if (_shaderClipping == null)
            {
                Debug.LogError("Shader Clipping is Null");
            }

            //RenderVert를 만들어주자
            _renderVerts = new apOptRenderVertex[_nVert];
            for (int i = 0; i < _nVert; i++)
            {
                _renderVerts[i] = new apOptRenderVertex(
                    _parentTransform, this,
                    _vertUniqueIDs[i], i,
                    new Vector2(vertPositions[i].x, vertPositions[i].y),
                    _vertUVs[i]);

                _renderVerts[i].SetMatrix_1_Static_Vert2Mesh(_matrix_Vert2Mesh);
                _renderVerts[i].SetMatrix_3_Transform_Mesh(parentTransform._matrix_TFResult_WorldWithoutMod.MtrxToSpace);
                _renderVerts[i].Calculate();
            }

            if (_meshFilter == null || _mesh == null)
            {
                _meshFilter = GetComponent <MeshFilter>();
                _mesh       = new Mesh();
                _mesh.name  = this.name + "_Mesh";

                _meshFilter.sharedMesh = _mesh;
            }

            if (_meshRenderer == null)
            {
                _meshRenderer = GetComponent <MeshRenderer>();

                //_material = new Material(Shader.Find("AnyPortrait/Transparent/Colored Texture (2X)"));
                //Debug.Log("Opt Shader : " + _shaderNormal.name + "(" + name + ")");
                //_material = new Material(Shader.Find(_shaderName));
                _material = new Material(_shaderNormal);
                _material.SetColor("_Color", new Color(0.5f, 0.5f, 0.5f, 1.0f));
                _material.SetTexture("_MainTex", _texture);

                _meshRenderer.sharedMaterial = _material;
            }

            _isMaskParent = false;
            _isMaskChild  = false;
            _clipParentID = -1;
            _clipChildIDs = null;

            _vertPositions_Updated = new Vector3[_vertPositions.Length];
            _vertPositions_Local   = new Vector3[_vertPositions.Length];
            for (int i = 0; i < _vertPositions.Length; i++)
            {
                //Calculate 전에는 직접 Pivot Pos를 적용해주자 (Calculate에서는 자동 적용)
                //_vertPositions_Updated[i] = _vertPositions[i] + new Vector3(_pivotPos.x, _pivotPos.y, 0);
                //_vertPositions_Updated[i] = _vertPositions[i];
                //_vertPositions_Updated[i] = _vertPositions[i] - new Vector3(_pivotPos.x, _pivotPos.y, 0);
                _vertPositions_Updated[i] = _renderVerts[i]._vertPos3_LocalUpdated;
            }
            //_texture_Updated = _texture;


            _transform = transform;

            InitMesh(true);

            RefreshMesh();
        }
Пример #9
0
        public bool Compute_Opt(apOptRenderVertex[] renderVerts,
                                apMatrix3x3 matrix_Static_Vert2Mesh,
                                apMatrix3x3 matrix_Static_Vert2Mesh_Inverse,
                                apMatrix3x3 matrix_MeshTransform,
                                ref Vector3[] targetVertList)
        {
            if (!IsSupport)
            {
                return(false);
            }

            Matrix2Floats(matrix_Static_Vert2Mesh, ref _matrix_Static_Vert2Mesh);
            Matrix2Floats(matrix_MeshTransform, ref _matrix_MeshTransform);
            Matrix2Floats(matrix_Static_Vert2Mesh_Inverse, ref _matrix_Static_Vert2MeshInverse);


            _cShader_Opt.SetFloats("_mtx_Static_Vert2Mesh", _matrix_Static_Vert2Mesh);
            _cShader_Opt.SetFloats("_mtx_MeshTransform", _matrix_MeshTransform);
            _cShader_Opt.SetFloats("_mtx_Static_Vert2MeshInverse", _matrix_Static_Vert2MeshInverse);

            _inputVerts_Opt  = new InputVertexStruct_Opt[renderVerts.Length];
            _outputVerts_Opt = new OutputVertexStruct_Opt[renderVerts.Length];

            int nRenderVerts             = renderVerts.Length;
            apOptRenderVertex renderVert = null;

            for (int i = 0; i < nRenderVerts; i++)
            {
                renderVert = renderVerts[i];
                _inputVerts_Opt[i]._posL       = renderVert._pos_Local;
                _inputVerts_Opt[i]._posRigging = renderVert._pos_Rigging;

                _inputVerts_Opt[i]._riggingWeight = renderVert._weight_Rigging;

                _inputVerts_Opt[i]._mtx_Cal_VertLocal = renderVert._matrix_Cal_VertLocal;
                _inputVerts_Opt[i]._mtx_Cal_VertWorld = renderVert._matrix_Cal_VertWorld;
            }
            _inputBuffer  = new ComputeBuffer(nRenderVerts, 156);
            _outputBuffer = new ComputeBuffer(nRenderVerts, 32);

            _inputBuffer.SetData(_inputVerts_Opt);

            _cShader_Opt.SetBuffer(_kernel_Opt, "_inputBuffer", _inputBuffer);
            _cShader_Opt.SetBuffer(_kernel_Opt, "_outputBuffer", _outputBuffer);

            _cShader_Opt.Dispatch(_kernel_Opt, 32, 32, 1);

            _outputBuffer.GetData(_outputVerts_Opt);

            for (int i = 0; i < nRenderVerts; i++)
            {
                renderVert = renderVerts[i];
                renderVert.CalculateByComputeShader(ref _outputVerts_Opt[i]);
                targetVertList[i] = renderVert._vertPos3_LocalUpdated;
            }

            _inputBuffer.Release();
            _outputBuffer.Release();

            _inputBuffer  = null;
            _outputBuffer = null;

            return(true);
        }
Пример #10
0
 public void Link(apOptRenderVertex linkedVertex, apOptModifiedPhysicsVertex linkedModPhysicsVertex)
 {
     _vertex        = linkedVertex;
     _modVertWeight = linkedModPhysicsVertex;
 }