示例#1
0
        //추가
        /// <summary>
        /// Modifier가 적용되지 않은 Render Vert의 World Position이 필요할때 이 함수를 호출하자.
        /// 결과값은 각 RenderVert의 _pos_World_NoMod에 저장된다.
        /// </summary>
        public void CalculateWorldPositionWithoutModifier()
        {
            //강제로 업데이트해야하는지 결정한다.
            //Child까지 계산한 이후 Vertex를 계산해줘야 한다.
            if (_unitType == UNIT_TYPE.Mesh)
            {
                apRenderVertex rVert = null;
                for (int i = 0; i < _renderVerts.Count; i++)
                {
                    rVert = _renderVerts[i];

                    rVert.CalculateNotModified(_meshTransform._mesh.Matrix_VertToLocal, WorldMatrixWrapWithoutModified.MtrxToSpace);
                }
            }

            //이건 필요한 RenderUnit만 따로 호출하므로 굳이 Child도 호출할 필요가 없다.
            //if (_childRenderUnits.Count > 0)
            //{
            //	apRenderUnit childRenderUnit = null;
            //	for (int i = 0; i < _childRenderUnits.Count; i++)
            //	{
            //		childRenderUnit = _childRenderUnits[i];

            //		childRenderUnit.CalculateWorldPositionWithoutModifier();
            //	}
            //}
        }
        public void Link(apModifiedMesh modifiedMesh, apMesh mesh, apVertex vertex)
        {
            _modifiedMesh = modifiedMesh;
            _mesh         = mesh;
            _vertex       = vertex;
            if (_vertex != null)
            {
                _vertIndex = _vertex._index;
            }
            else
            {
                _vertIndex = -1;
            }

            _renderVertex = null;
            if (modifiedMesh._renderUnit != null && _vertex != null)
            {
                _renderVertex = modifiedMesh._renderUnit._renderVerts.Find(delegate(apRenderVertex a)
                {
                    return(a._vertex == _vertex);
                });
            }

            if (_physicParam == null)
            {
                _physicParam = new apPhysicsVertParam();
            }

            _physicParam.Link(modifiedMesh, this);

            RefreshModMeshAndWeights(_modifiedMesh);
        }
            public Vector2 _cal_VertWorld;              //64

            public RenderRequest(apRenderUnit renderUnit,
                                 apRenderVertex renderVert,
                                 apMatrix3x3 matrix_Static_Vert2Mesh,
                                 apMatrix3x3 matrix_MeshTransform,
                                 apMatrix3x3 matrix_MeshTransformInverse,
                                 int iVert,
                                 Vector2 posL,
                                 float riggingWeight,
                                 Vector2 posRigging,
                                 Vector2 cal_VertLocal,
                                 Vector2 cal_VertWorld
                                 )
            {
                _renderUnit = renderUnit;
                _renderVert = renderVert;
                _matrix_Static_Vert2Mesh     = matrix_Static_Vert2Mesh;
                _matrix_MeshTransform        = matrix_MeshTransform;
                _matrix_MeshTransformInverse = matrix_MeshTransformInverse;
                _iVert         = iVert;
                _posL          = posL;
                _riggingWeight = riggingWeight;
                _posRigging    = posRigging;
                _cal_VertLocal = cal_VertLocal;
                _cal_VertWorld = cal_VertWorld;
            }
示例#4
0
 public void RefreshModMeshAndRenderVertex(apModifiedMesh modifiedMesh)
 {
     if (_modifiedMesh != modifiedMesh || _renderVertex == null)
     {
         _modifiedMesh = modifiedMesh;
         if (_modifiedMesh != null && modifiedMesh._renderUnit != null && _vertex != null)
         {
             _renderVertex = modifiedMesh._renderUnit._renderVerts.Find(delegate(apRenderVertex a)
             {
                 return(a._vertex == _vertex);
             });
         }
     }
 }
        // 단축키 : 버텍스 전체 선택
        private void OnHotKeyEvent__Modifier_Physics__Ctrl_A(object paramObject)
        {
            if (Editor.Select.MeshGroup == null || Editor.Select.Modifier == null)
            {
                return;
            }


            if (Editor.Select.ModRenderVertListOfMod == null)
            {
                return;
            }

            if (Editor.Select.ExEditingMode != apSelection.EX_EDIT.None && Editor.Select.ExKey_ModMesh != null && Editor.Select.MeshGroup != null)
            {
                //선택된 RenderUnit을 고르자
                apRenderUnit targetRenderUnit = Editor.Select.MeshGroup.GetRenderUnit(Editor.Select.ExKey_ModMesh._transform_Mesh);

                if (targetRenderUnit != null)
                {
                    //모든 버텍스를 선택
                    for (int iVert = 0; iVert < targetRenderUnit._renderVerts.Count; iVert++)
                    {
                        apRenderVertex renderVert = targetRenderUnit._renderVerts[iVert];

                        apModifiedVertexWeight selectedModVertWeight = Editor.Select.ExKey_ModMesh._vertWeights.Find(delegate(apModifiedVertexWeight a)
                        {
                            return(renderVert._vertex._uniqueID == a._vertexUniqueID);
                        });
                        Editor.Select.AddModVertexOfModifier(null, null, selectedModVertWeight, renderVert);
                    }

                    Editor.Gizmos.SetSelectResultForce_Multiple <apSelection.ModRenderVert>(Editor.Select.ModRenderVertListOfMod);

                    Editor.RefreshControllerAndHierarchy(false);
                    //Editor.Repaint();
                    Editor.SetRepaint();

                    Editor.Select.AutoSelectModMeshOrModBone();
                }
            }
        }
示例#6
0
        public void Link(apModifiedMesh modifiedMesh, apMesh mesh, apVertex vertex)
        {
            _modifiedMesh = modifiedMesh;
            _mesh         = mesh;
            _vertex       = vertex;
            if (_vertex != null)
            {
                _vertIndex = _vertex._index;
            }
            else
            {
                _vertIndex = -1;
            }

            _renderVertex = null;
            if (modifiedMesh._renderUnit != null && _vertex != null)
            {
                _renderVertex = modifiedMesh._renderUnit._renderVerts.Find(delegate(apRenderVertex a)
                {
                    return(a._vertex == _vertex);
                });
            }
        }
示例#7
0
        /// <summary>
        /// Update를 끝내고 호출해야하는 함수
        /// 갱신된 정보를 RenderVertex 정보로 넣어준다.
        /// Child RenderUnit에 자동으로 호출한다.
        /// </summary>
        /// <param name="isUpdateAlways">Vertex 작업을 하는 상태에서는 True를 넣는다. 재생 전용이고 Gizmo가 안뜨면 False를 넣어주자</param>
        /// <param name="isMatrixCalculateForce">Matrix를 강제로 넣어야 한다. Force 옵션 또는 tDelta > bias일때 true 값을 넣자</param>
        //public void UpdateToRenderVert(float tDelta, bool isUpdateAlways, bool isMatrixCalculateForce, apMeshGroup.FUNC_IS_FORCE_UPDATE funcForceUpdate)
        //public void UpdateToRenderVert(float tDelta, bool isUpdateAlways, bool isMatrixCalculateForce, apMeshGroup.FUNC_IS_FORCE_UPDATE funcForceUpdate)
        public void UpdateToRenderVert(float tDelta, bool isUpdateAlways)
        {
            //강제로 업데이트해야하는지 결정한다.

            //Profiler.BeginSample("1. Func Check");
            //if(!isMatrixCalculateForce && funcForceUpdate != null)
            //{
            //	isMatrixCalculateForce = funcForceUpdate(this);
            //}
            //Profiler.EndSample();

            //Child까지 계산한 이후 Vertex를 계산해줘야 한다.
            if (_unitType == UNIT_TYPE.Mesh && (isUpdateAlways || _isVisible))
            {
                bool isRigging     = _calculatedStack.IsRigging;
                bool isVertexLocal = _calculatedStack.IsVertexLocal;
                bool isVertexWorld = _calculatedStack.IsVertexWorld;

                apRenderVertex rVert = null;

                for (int i = 0; i < _renderVerts.Count; i++)
                {
                    rVert = _renderVerts[i];

                    rVert.ReadyToCalculate();

                    //단계별로 처리하자

                    //1) Pivot 위치 적용
                    //rVert.SetMatrix_1_Static_Vert2Mesh(_meshTransform._mesh.Matrix_VertToLocal, _meshTransform._mesh.MatrixHashCode);
                    rVert.SetMatrix_1_Static_Vert2Mesh(_meshTransform._mesh.Matrix_VertToLocal);

                    if (isRigging)
                    {
                        rVert.SetRigging_0_LocalPosWeight(_calculatedStack.GetVertexRigging(i), _calculatedStack.GetRiggingWeight(), _calculatedStack.GetMatrixRigging(i));
                    }

                    if (isVertexLocal)
                    {
                        //Calculate - Vertex Local Morph (Vec2)
                        rVert.SetMatrix_2_Calculate_VertLocal(_calculatedStack.GetVertexLocalPos(i));
                    }

                    rVert.SetMatrix_3_Transform_Mesh(WorldMatrix);

                    if (isVertexWorld)
                    {
                        //Calculate - Vertex World Morph (Vec2)
                        rVert.SetMatrix_4_Calculate_VertWorld(_calculatedStack.GetVertexWorldPos(i));
                    }

                    rVert.Calculate(tDelta);
                }
            }

            if (_childRenderUnits.Count > 0)
            {
                apRenderUnit childRenderUnit = null;
                for (int i = 0; i < _childRenderUnits.Count; i++)
                {
                    childRenderUnit = _childRenderUnits[i];

                    //childRenderUnit.UpdateToRenderVert(tDelta, isUpdateAlways, isMatrixCalculateForce, funcForceUpdate);
                    childRenderUnit.UpdateToRenderVert(tDelta, isUpdateAlways);
                }
            }
        }
        /// <summary>
        /// Physic Modifier내에서의 Gizmo 이벤트 : Vertex 계열 선택시 [단일 선택]
        /// </summary>
        /// <param name="mousePosGL"></param>
        /// <param name="mousePosW"></param>
        /// <param name="btnIndex"></param>
        /// <param name="selectType"></param>
        /// <returns></returns>
        public apGizmos.SelectResult Select__Modifier_Physics(Vector2 mousePosGL, Vector2 mousePosW, int btnIndex, apGizmos.SELECT_TYPE selectType)
        {
            if (Editor.Select.MeshGroup == null || Editor.Select.Modifier == null)
            {
                return(null);
            }

            //(Editing 상태일 때)
            //1. Vertex 선택
            //2. (Lock 걸리지 않았다면) 다른 Transform을 선택

            //(Editing 상태가 아닐 때)
            //(Lock 걸리지 않았다면) Transform을 선택한다.
            // Child 선택이 가능하면 MeshTransform을 선택. 그렇지 않아면 MeshGroupTransform을 선택해준다.

            if (Editor.Select.ModRenderVertListOfMod == null)
            {
                return(null);
            }

            int prevSelectedCount = Editor.Select.ModRenderVertListOfMod.Count;

            if (!Editor.Controller.IsMouseInGUI(mousePosGL))
            {
                return(apGizmos.SelectResult.Main.SetMultiple <apSelection.ModRenderVert>(Editor.Select.ModRenderVertListOfMod));
            }

            bool isChildMeshTransformSelectable = Editor.Select.Modifier.IsTarget_ChildMeshTransform;

            //apGizmos.SELECT_RESULT result = apGizmos.SELECT_RESULT.None;

            bool isTransformSelectable = false;

            if (Editor.Select.ExEditingMode != apSelection.EX_EDIT.None)
            {
                //(Editing 상태일 때)
                //1. Vertex 선택
                //2. (Lock 걸리지 않았다면) 다른 Transform을 선택
                bool selectVertex = false;
                if (Editor.Select.ExKey_ModMesh != null && Editor.Select.MeshGroup != null)
                {
                    //일단 선택한 Vertex가 클릭 가능한지 체크
                    if (Editor.Select.ModRenderVertOfMod != null)
                    {
                        if (Editor.Select.ModRenderVertListOfMod.Count == 1)
                        {
                            if (Editor.Controller.IsVertexClickable(apGL.World2GL(Editor.Select.ModRenderVertOfMod._renderVert._pos_World), mousePosGL))
                            {
                                if (selectType == apGizmos.SELECT_TYPE.Subtract)
                                {
                                    //삭제인 경우 : ModVertWeight를 선택한다.
                                    Editor.Select.RemoveModVertexOfModifier(null, null, Editor.Select.ModRenderVertOfMod._modVertWeight, Editor.Select.ModRenderVertOfMod._renderVert);
                                }
                                else
                                {
                                    //그 외에는 => 그대로 갑시다.
                                    selectVertex = true;
                                    //return apGizmos.SELECT_RESULT.SameSelected;
                                }
                                //return Editor.Select.ModRenderVertListOfMod.Count;
                                return(apGizmos.SelectResult.Main.SetMultiple <apSelection.ModRenderVert>(Editor.Select.ModRenderVertListOfMod));
                            }
                        }
                        else
                        {
                            //여러개라고 하네요.
                            List <apSelection.ModRenderVert> modRenderVerts = Editor.Select.ModRenderVertListOfMod;
                            for (int iModRenderVert = 0; iModRenderVert < modRenderVerts.Count; iModRenderVert++)
                            {
                                apSelection.ModRenderVert modRenderVert = modRenderVerts[iModRenderVert];

                                if (Editor.Controller.IsVertexClickable(apGL.World2GL(modRenderVert._renderVert._pos_World), mousePosGL))
                                {
                                    if (selectType == apGizmos.SELECT_TYPE.Subtract)
                                    {
                                        //삭제인 경우
                                        //하나 지우고 끝
                                        //결과는 List의 개수
                                        Editor.Select.RemoveModVertexOfModifier(null, null, modRenderVert._modVertWeight, modRenderVert._renderVert);
                                    }
                                    else if (selectType == apGizmos.SELECT_TYPE.Add)
                                    {
                                        //Add 상태에서 원래 선택된걸 누른다면
                                        //추가인 경우 => 그대로
                                        selectVertex = true;
                                    }
                                    else
                                    {
                                        //만약... new 라면?
                                        //다른건 초기화하고
                                        //얘만 선택해야함
                                        apRenderVertex         selectedRenderVert    = modRenderVert._renderVert;
                                        apModifiedVertexWeight selectedModVertWeight = modRenderVert._modVertWeight;
                                        Editor.Select.SetModVertexOfModifier(null, null, null, null);
                                        Editor.Select.SetModVertexOfModifier(null, null, selectedModVertWeight, selectedRenderVert);
                                    }

                                    //return Editor.Select.ModRenderVertListOfMod.Count;
                                    return(apGizmos.SelectResult.Main.SetMultiple <apSelection.ModRenderVert>(Editor.Select.ModRenderVertListOfMod));
                                }
                            }
                        }
                    }

                    if (selectType == apGizmos.SELECT_TYPE.New)
                    {
                        //Add나 Subtract가 아닐땐, 잘못 클릭하면 선택을 해제하자 (전부)
                        Editor.Select.SetModVertexOfModifier(null, null, null, null);
                    }

                    if (selectType != apGizmos.SELECT_TYPE.Subtract)
                    {
                        if (Editor.Select.ExKey_ModMesh._transform_Mesh != null &&
                            Editor.Select.ExKey_ModMesh._vertices != null)
                        {
                            //선택된 RenderUnit을 고르자
                            apRenderUnit targetRenderUnit = Editor.Select.MeshGroup.GetRenderUnit(Editor.Select.ExKey_ModMesh._transform_Mesh);

                            if (targetRenderUnit != null)
                            {
                                for (int iVert = 0; iVert < targetRenderUnit._renderVerts.Count; iVert++)
                                {
                                    apRenderVertex renderVert = targetRenderUnit._renderVerts[iVert];
                                    bool           isClick    = Editor.Controller.IsVertexClickable(apGL.World2GL(renderVert._pos_World), mousePosGL);
                                    if (isClick)
                                    {
                                        apModifiedVertexWeight selectedModVertWeight = Editor.Select.ExKey_ModMesh._vertWeights.Find(delegate(apModifiedVertexWeight a)
                                        {
                                            return(renderVert._vertex._uniqueID == a._vertexUniqueID);
                                        });

                                        if (selectedModVertWeight != null)
                                        {
                                            if (selectType == apGizmos.SELECT_TYPE.New)
                                            {
                                                Editor.Select.SetModVertexOfModifier(null, null, selectedModVertWeight, renderVert);
                                            }
                                            else if (selectType == apGizmos.SELECT_TYPE.Add)
                                            {
                                                Editor.Select.AddModVertexOfModifier(null, null, selectedModVertWeight, renderVert);
                                            }

                                            selectVertex = true;
                                            //result = apGizmos.SELECT_RESULT.NewSelected;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                //Vertex를 선택한게 없다면
                //+ Lock 상태가 아니라면
                if (!selectVertex && !Editor.Select.IsLockExEditKey)
                {
                    //Transform을 선택
                    isTransformSelectable = true;
                }
            }
            else
            {
                //(Editing 상태가 아닐때)
                isTransformSelectable = true;

                if (Editor.Select.ExKey_ModMesh != null && Editor.Select.IsLockExEditKey)
                {
                    //뭔가 선택된 상태에서 Lock이 걸리면 다른건 선택 불가
                    isTransformSelectable = false;
                }
            }

            if (isTransformSelectable && selectType == apGizmos.SELECT_TYPE.New)
            {
                //(Editing 상태가 아닐 때)
                //Transform을 선택한다.

                apTransform_Mesh selectedMeshTransform = null;

                List <apRenderUnit> renderUnits = Editor.Select.MeshGroup._renderUnits_All;               //<<정렬된 Render Unit
                for (int iUnit = 0; iUnit < renderUnits.Count; iUnit++)
                {
                    apRenderUnit renderUnit = renderUnits[iUnit];
                    if (renderUnit._meshTransform != null && renderUnit._meshTransform._mesh != null)
                    {
                        if (renderUnit._meshTransform._isVisible_Default && renderUnit._meshColor2X.a > 0.1f)                        //Alpha 옵션 추가
                        {
                            //Debug.LogError("TODO : Mouse Picking 바꿀것");
                            bool isPick = apEditorUtil.IsMouseInRenderUnitMesh(
                                mousePosGL, renderUnit);

                            if (isPick)
                            {
                                selectedMeshTransform = renderUnit._meshTransform;
                                //찾았어도 계속 찾는다.
                                //뒤의 아이템이 "앞쪽"에 있는 것이기 때문
                            }
                        }
                    }
                }

                if (selectedMeshTransform != null)
                {
                    //만약 ChildMeshGroup에 속한 거라면,
                    //Mesh Group 자체를 선택해야 한다. <- 추가 : Child Mesh Transform이 허용되는 경우 그럴 필요가 없다.
                    apMeshGroup parentMeshGroup = Editor.Select.MeshGroup.FindParentMeshGroupOfMeshTransform(selectedMeshTransform);
                    if (parentMeshGroup == null || parentMeshGroup == Editor.Select.MeshGroup || isChildMeshTransformSelectable)
                    {
                        Editor.Select.SetSubMeshInGroup(selectedMeshTransform);
                    }
                    else
                    {
                        apTransform_MeshGroup childMeshGroupTransform = Editor.Select.MeshGroup.FindChildMeshGroupTransform(parentMeshGroup);
                        if (childMeshGroupTransform != null)
                        {
                            Editor.Select.SetSubMeshGroupInGroup(childMeshGroupTransform);
                        }
                        else
                        {
                            Editor.Select.SetSubMeshInGroup(selectedMeshTransform);
                        }
                    }
                }
                else
                {
                    Editor.Select.SetSubMeshInGroup(null);
                }

                Editor.RefreshControllerAndHierarchy();
                //Editor.Repaint();
                Editor.SetRepaint();
            }

            //개수에 따라 한번더 결과 보정
            if (Editor.Select.ModRenderVertListOfMod != null)
            {
                //return Editor.Select.ModRenderVertListOfMod.Count;
                return(apGizmos.SelectResult.Main.SetMultiple <apSelection.ModRenderVert>(Editor.Select.ModRenderVertListOfMod));
            }
            return(null);
        }
        /// <summary>
        /// Physics Modifier내에서의 Gizmo 이벤트 : Vertex 계열 선택시 [복수 선택]
        /// </summary>
        /// <param name="mousePosGL_Min"></param>
        /// <param name="mousePosGL_Max"></param>
        /// <param name="mousePosW_Min"></param>
        /// <param name="mousePosW_Max"></param>
        /// <param name="areaSelectType"></param>
        /// <returns></returns>
        public apGizmos.SelectResult MultipleSelect__Modifier_Physics(Vector2 mousePosGL_Min, Vector2 mousePosGL_Max, Vector2 mousePosW_Min, Vector2 mousePosW_Max, apGizmos.SELECT_TYPE areaSelectType)
        {
            if (Editor.Select.MeshGroup == null || Editor.Select.Modifier == null)
            {
                return(null);
            }


            if (Editor.Select.ModRenderVertListOfMod == null)
            {
                return(null);
            }
            // 이건 다중 버텍스 선택밖에 없다.
            //Transform 선택은 없음


            bool isAnyChanged = false;

            if (Editor.Select.ExEditingMode != apSelection.EX_EDIT.None && Editor.Select.ExKey_ModMesh != null && Editor.Select.MeshGroup != null)
            {
                //선택된 RenderUnit을 고르자
                apRenderUnit targetRenderUnit = Editor.Select.MeshGroup.GetRenderUnit(Editor.Select.ExKey_ModMesh._transform_Mesh);

                if (targetRenderUnit != null)
                {
                    for (int iVert = 0; iVert < targetRenderUnit._renderVerts.Count; iVert++)
                    {
                        apRenderVertex renderVert   = targetRenderUnit._renderVerts[iVert];
                        bool           isSelectable = (mousePosW_Min.x < renderVert._pos_World.x && renderVert._pos_World.x < mousePosW_Max.x) &&
                                                      (mousePosW_Min.y < renderVert._pos_World.y && renderVert._pos_World.y < mousePosW_Max.y);
                        if (isSelectable)
                        {
                            apModifiedVertexWeight selectedModVertWeight = Editor.Select.ExKey_ModMesh._vertWeights.Find(delegate(apModifiedVertexWeight a)
                            {
                                return(renderVert._vertex._uniqueID == a._vertexUniqueID);
                            });

                            if (selectedModVertWeight != null)
                            {
                                if (areaSelectType == apGizmos.SELECT_TYPE.Add ||
                                    areaSelectType == apGizmos.SELECT_TYPE.New)
                                {
                                    Editor.Select.AddModVertexOfModifier(null, null, selectedModVertWeight, renderVert);
                                }
                                else
                                {
                                    Editor.Select.RemoveModVertexOfModifier(null, null, selectedModVertWeight, renderVert);
                                }

                                isAnyChanged = true;
                            }
                        }
                    }

                    Editor.RefreshControllerAndHierarchy();
                    //Editor.Repaint();
                    Editor.SetRepaint();
                }
            }


            if (isAnyChanged)
            {
                Editor.Select.AutoSelectModMeshOrModBone();
            }

            //return Editor.Select.ModRenderVertListOfMod.Count;
            return(apGizmos.SelectResult.Main.SetMultiple <apSelection.ModRenderVert>(Editor.Select.ModRenderVertListOfMod));
        }
示例#10
0
        /// <summary>
        /// Rigging Modifier 내에서의 Gizmo 이벤트 : Vertex 선택 또는 Bone 선택 [단일 선택]
        /// </summary>
        /// <param name="mousePosGL"></param>
        /// <param name="mousePosW"></param>
        /// <param name="btnIndex"></param>
        /// <param name="selectType"></param>
        /// <returns></returns>
        public apGizmos.SelectResult Select__Modifier_Rigging(Vector2 mousePosGL, Vector2 mousePosW, int btnIndex, apGizmos.SELECT_TYPE selectType)
        {
            if (Editor.Select.MeshGroup == null || Editor.Select.Modifier == null)
            {
                return(null);
            }

            // 선택은 Test Posing 상관없이 수행한다.
            // - Vertex > (선택 못했어도 일단 이전에 선택한 Vertex를 해제하지 않는다.)
            // - Bone > (선택 못했으면 이전에 선택한 Bone 해제)
            // Vertex나 Bone 선택이 되지 않았다면, 이전에 선택했던 Vertex, Bone을 모두 해제한다.

            // - Mesh Transform 선택 (Lock이 안걸린 경우. 이건 리턴하지 않는다)
            // (아무것도 선택하지 않은 경우) -> Vertex, Bone, Mesh Transform 해제

            bool isAnySelected = false;


            if (Editor.Select.ModRenderVertListOfMod == null)
            {
                return(null);
            }



            if (!Editor.Controller.IsMouseInGUI(mousePosGL))
            {
                if (Editor.Select.ModRenderVertListOfMod.Count > 0)
                {
                    return(apGizmos.SelectResult.Main.SetMultiple <apSelection.ModRenderVert>(Editor.Select.ModRenderVertListOfMod));
                }
                if (Editor.Select.Bone != null)
                {
                    return(apGizmos.SelectResult.Main.SetSingle(Editor.Select.Bone));
                }
                return(null);
            }
            int  prevSelectedVertex  = Editor.Select.ModRenderVertListOfMod.Count;
            bool isAnyVertexSelected = false;
            bool isAnyBoneSelected   = false;
            List <apSelection.ModRenderVert> prevSelectedVertices = new List <apSelection.ModRenderVert>();

            for (int i = 0; i < Editor.Select.ModRenderVertListOfMod.Count; i++)
            {
                prevSelectedVertices.Add(Editor.Select.ModRenderVertListOfMod[i]);
            }

            //1. 버텍스 선택을 먼저
            bool isChildMeshTransformSelectable = Editor.Select.Modifier.IsTarget_ChildMeshTransform;


            if (Editor.Select.ExKey_ModMesh != null && Editor.Select.MeshGroup != null)
            {
                //bool selectVertex = false;
                //일단 선택한 Vertex가 클릭 가능한지 체크
                if (Editor.Select.ModRenderVertOfMod != null)
                {
                    if (Editor.Select.ModRenderVertListOfMod.Count == 1)
                    {
                        if (Editor.Controller.IsVertexClickable(apGL.World2GL(Editor.Select.ModRenderVertOfMod._renderVert._pos_World), mousePosGL))
                        {
                            if (selectType == apGizmos.SELECT_TYPE.Subtract)
                            {
                                //삭제인 경우
                                //ModVert가 아니라 ModVertRig인 점 주의
                                Editor.Select.RemoveModVertexOfModifier(null, Editor.Select.ModRenderVertOfMod._modVertRig, null, Editor.Select.ModRenderVertOfMod._renderVert);
                                //return apGizmos.SELECT_RESULT.None;
                            }
                            else
                            {
                                //그 외에는 => 그대로 갑시다.
                                isAnySelected = true;
                                //return apGizmos.SELECT_RESULT.SameSelected;
                            }
                            //return Editor.Select.ModRenderVertListOfMod.Count;
                            return(apGizmos.SelectResult.Main.SetMultiple <apSelection.ModRenderVert>(Editor.Select.ModRenderVertListOfMod));
                        }
                    }
                    else
                    {
                        //여러개라고 하네요.
                        List <apSelection.ModRenderVert> modRenderVerts = Editor.Select.ModRenderVertListOfMod;
                        for (int iModRenderVert = 0; iModRenderVert < modRenderVerts.Count; iModRenderVert++)
                        {
                            apSelection.ModRenderVert modRenderVert = modRenderVerts[iModRenderVert];

                            if (Editor.Controller.IsVertexClickable(apGL.World2GL(modRenderVert._renderVert._pos_World), mousePosGL))
                            {
                                if (selectType == apGizmos.SELECT_TYPE.Subtract)
                                {
                                    //삭제인 경우
                                    //하나 지우고 끝
                                    //결과는 List의 개수
                                    Editor.Select.RemoveModVertexOfModifier(null, modRenderVert._modVertRig, null, modRenderVert._renderVert);
                                }
                                else if (selectType == apGizmos.SELECT_TYPE.Add)
                                {
                                    //Add 상태에서 원래 선택된걸 누른다면
                                    //추가인 경우 => 그대로
                                    isAnySelected = true;
                                }
                                else
                                {
                                    //만약... new 라면?
                                    //다른건 초기화하고
                                    //얘만 선택해야함
                                    apRenderVertex      selectedRenderVert = modRenderVert._renderVert;
                                    apModifiedVertexRig selectedModVertRig = modRenderVert._modVertRig;
                                    Editor.Select.SetModVertexOfModifier(null, null, null, null);
                                    Editor.Select.SetModVertexOfModifier(null, selectedModVertRig, null, selectedRenderVert);
                                    //return apGizmos.SELECT_RESULT.NewSelected;
                                    //return Editor.Select.ModRenderVertOfModList.Count;
                                }

                                //return Editor.Select.ModRenderVertListOfMod.Count;
                                return(apGizmos.SelectResult.Main.SetMultiple <apSelection.ModRenderVert>(Editor.Select.ModRenderVertListOfMod));
                            }
                        }
                    }
                }

                //이부분 주의
                //일단 날리되, "Bone을 선택했다면 이전에 선택한 vertex를 유지한다"를 지켜야한다.
                if (selectType == apGizmos.SELECT_TYPE.New)
                {
                    //Add나 Subtract가 아닐땐, 잘못 클릭하면 선택을 해제하자 (전부)
                    Editor.Select.SetModVertexOfModifier(null, null, null, null);
                }

                if (selectType != apGizmos.SELECT_TYPE.Subtract)
                {
                    if (Editor.Select.ExKey_ModMesh._transform_Mesh != null &&
                        Editor.Select.ExKey_ModMesh._vertRigs != null)
                    {
                        //선택된 RenderUnit을 고르자
                        apRenderUnit targetRenderUnit = Editor.Select.MeshGroup.GetRenderUnit(Editor.Select.ExKey_ModMesh._transform_Mesh);

                        if (targetRenderUnit != null)
                        {
                            for (int iVert = 0; iVert < targetRenderUnit._renderVerts.Count; iVert++)
                            {
                                apRenderVertex renderVert = targetRenderUnit._renderVerts[iVert];
                                bool           isClick    = Editor.Controller.IsVertexClickable(apGL.World2GL(renderVert._pos_World), mousePosGL);
                                if (isClick)
                                {
                                    apModifiedVertexRig selectedModVertRig = Editor.Select.ExKey_ModMesh._vertRigs.Find(delegate(apModifiedVertexRig a)
                                    {
                                        return(renderVert._vertex._uniqueID == a._vertexUniqueID);
                                    });

                                    if (selectedModVertRig != null)
                                    {
                                        if (selectType == apGizmos.SELECT_TYPE.New)
                                        {
                                            Editor.Select.SetModVertexOfModifier(null, selectedModVertRig, null, renderVert);
                                        }
                                        else if (selectType == apGizmos.SELECT_TYPE.Add)
                                        {
                                            Editor.Select.AddModVertexOfModifier(null, selectedModVertRig, null, renderVert);
                                        }

                                        isAnySelected       = true;
                                        isAnyVertexSelected = true;

                                        //result = apGizmos.SELECT_RESULT.NewSelected;
                                        break;
                                    }
                                }
                            }

                            Editor.RefreshControllerAndHierarchy();
                            //Editor.Repaint();
                            Editor.SetRepaint();
                        }
                    }
                }

                if (isAnySelected)
                {
                    Editor.Select.AutoSelectModMeshOrModBone();
                }
            }

            if (!Editor.Select.IsLockExEditKey)
            {
                if (!isAnySelected)
                {
                    //2. Bone을 선택하자
                    //Bone은 Select Mode가 Subtract가 아닌 이상 무조건 작동을 한다.
                    //만약, 잠금 버튼이 눌렸다면 -> Bone 선택하지 않았어도 해제를 하지 않는다.
                    apMeshGroup meshGroup = Editor.Select.MeshGroup;
                    apBone      prevBone  = Editor.Select.Bone;

                    List <apBone> boneList = meshGroup._boneList_All;
                    apBone        bone     = null;
                    for (int i = 0; i < boneList.Count; i++)
                    {
                        bone = boneList[i];
                        if (IsBoneClick(bone, mousePosW, mousePosGL, Editor._boneGUIRenderMode == apEditor.BONE_RENDER_MODE.RenderOutline))
                        {
                            //Debug.Log("Selected : " + bone._name);
                            if (selectType != apGizmos.SELECT_TYPE.Subtract)
                            {
                                Editor.Select.SetBone(bone);
                                isAnySelected = true;
                            }
                            else
                            {
                                Editor.Select.SetBone(null);
                            }

                            isAnyBoneSelected = true;

                            break;
                        }
                    }

                    if (!isAnySelected)
                    {
                        Editor.Select.SetBone(null);
                        if (Editor.Select.IsLockExEditKey)
                        {
                            Editor.Select.SetBone(prevBone);                            //복구
                        }
                    }
                    else
                    {
                        //Bone을 선택했다면
                        //Vertex를 복구해주자
                        for (int i = 0; i < prevSelectedVertices.Count; i++)
                        {
                            apSelection.ModRenderVert modRenderVert = prevSelectedVertices[i];
                            Editor.Select.AddModVertexOfModifier(modRenderVert._modVert, modRenderVert._modVertRig, null, modRenderVert._renderVert);
                        }
                    }

                    if (prevBone != Editor.Select.Bone)
                    {
                        _isBoneSelect_MovePosReset = true;
                        Editor.RefreshControllerAndHierarchy();
                    }
                }
            }


            if (!Editor.Select.IsLockExEditKey)
            {
                if (!isAnySelected && selectType == apGizmos.SELECT_TYPE.New)
                {
                    //3. Mesh Transform을 선택하자
                    //이건 선택 영역에 포함되지 않는다.
                    apTransform_Mesh selectedMeshTransform = null;

                    List <apRenderUnit> renderUnits = Editor.Select.MeshGroup._renderUnits_All;                   //<<정렬된 Render Unit
                    for (int iUnit = 0; iUnit < renderUnits.Count; iUnit++)
                    {
                        apRenderUnit renderUnit = renderUnits[iUnit];
                        if (renderUnit._meshTransform != null && renderUnit._meshTransform._mesh != null)
                        {
                            if (renderUnit._meshTransform._isVisible_Default && renderUnit._meshColor2X.a > 0.1f)                            //Alpha 옵션 추가
                            {
                                //Debug.LogError("TODO : Mouse Picking 바꿀것");
                                bool isPick = apEditorUtil.IsMouseInRenderUnitMesh(
                                    mousePosGL, renderUnit);

                                if (isPick)
                                {
                                    selectedMeshTransform = renderUnit._meshTransform;
                                    //찾았어도 계속 찾는다.
                                    //뒤의 아이템이 "앞쪽"에 있는 것이기 때문
                                }
                            }
                        }
                    }

                    if (selectedMeshTransform != null)
                    {
                        //만약 ChildMeshGroup에 속한 거라면,
                        //Mesh Group 자체를 선택해야 한다. <- 추가 : Child Mesh Transform이 허용되는 경우 그럴 필요가 없다.
                        apMeshGroup parentMeshGroup = Editor.Select.MeshGroup.FindParentMeshGroupOfMeshTransform(selectedMeshTransform);
                        if (parentMeshGroup == null || parentMeshGroup == Editor.Select.MeshGroup || isChildMeshTransformSelectable)
                        {
                            Editor.Select.SetSubMeshInGroup(selectedMeshTransform);
                        }
                        else
                        {
                            apTransform_MeshGroup childMeshGroupTransform = Editor.Select.MeshGroup.FindChildMeshGroupTransform(parentMeshGroup);
                            if (childMeshGroupTransform != null)
                            {
                                Editor.Select.SetSubMeshGroupInGroup(childMeshGroupTransform);
                            }
                            else
                            {
                                Editor.Select.SetSubMeshInGroup(selectedMeshTransform);
                            }
                        }
                    }
                    else
                    {
                        Editor.Select.SetSubMeshInGroup(null);
                    }

                    Editor.RefreshControllerAndHierarchy();
                    //Editor.Repaint();
                    Editor.SetRepaint();
                }
            }

            if (isAnySelected)
            {
                if (Editor.Select.ModRenderVertListOfMod != null && Editor.Select.ModRenderVertListOfMod.Count > 0)
                {
                    //return Editor.Select.ModRenderVertListOfMod.Count;
                    return(apGizmos.SelectResult.Main.SetMultiple <apSelection.ModRenderVert>(Editor.Select.ModRenderVertListOfMod));
                }

                if (Editor.Select.Bone != null)
                {
                    return(apGizmos.SelectResult.Main.SetSingle(Editor.Select.Bone));
                }
            }

            return(null);
        }
示例#11
0
        /// <summary>
        /// Update를 끝내고 호출해야하는 함수
        /// 갱신된 정보를 RenderVertex 정보로 넣어준다.
        /// Child RenderUnit에 자동으로 호출한다.
        /// </summary>
        /// <param name="isUpdateAlways">Vertex 작업을 하는 상태에서는 True를 넣는다. 재생 전용이고 Gizmo가 안뜨면 False를 넣어주자</param>
        /// <param name="isMatrixCalculateForce">Matrix를 강제로 넣어야 한다. Force 옵션 또는 tDelta > bias일때 true 값을 넣자</param>
        //public void UpdateToRenderVert(float tDelta, bool isUpdateAlways, bool isMatrixCalculateForce, apMeshGroup.FUNC_IS_FORCE_UPDATE funcForceUpdate)
        //public void UpdateToRenderVert(float tDelta, bool isUpdateAlways, bool isMatrixCalculateForce, apMeshGroup.FUNC_IS_FORCE_UPDATE funcForceUpdate)
        public void UpdateToRenderVert(float tDelta, bool isUpdateAlways)
        {
            //강제로 업데이트해야하는지 결정한다.

            //Profiler.BeginSample("1. Func Check");
            //if(!isMatrixCalculateForce && funcForceUpdate != null)
            //{
            //	isMatrixCalculateForce = funcForceUpdate(this);
            //}
            //Profiler.EndSample();

            //Child까지 계산한 이후 Vertex를 계산해줘야 한다.
            if (_unitType == UNIT_TYPE.Mesh && (isUpdateAlways || _isVisible))
            {
                bool isRigging     = _calculatedStack.IsRigging;
                bool isVertexLocal = _calculatedStack.IsVertexLocal;
                bool isVertexWorld = _calculatedStack.IsVertexWorld;

                apRenderVertex rVert = null;

                //Compute Shader를 써보자
                if (apComputeShader.I.IsComputable && _portrait._isGPUAccel)
                {
                    Profiler.BeginSample("2. Buffer Init");
                    int nVert = _renderVerts.Count;

                    if (_computedVerts_Input == null || _computedVerts_Input.Length != _renderVerts.Count)
                    {
                        _computedVerts_Input  = new ComputedVert_Input[nVert];
                        _computedVerts_Output = new ComputedVert_Output[nVert];
                    }

                    Profiler.EndSample();


                    float riggingWeight = 0.0f;
                    if (isRigging)
                    {
                        riggingWeight = _calculatedStack.GetRiggingWeight();
                    }


                    Profiler.BeginSample("3. Make Buffer");
                    for (int i = 0; i < nVert; i++)
                    {
                        rVert = _renderVerts[i];
                        //if (isMatrixCalculateForce)
                        //{
                        //	rVert.ResetMatrixHashCode();
                        //}
                        rVert.ReadyToCalculate();
                        //rVert.SetMatrix_1_Static_Vert2Mesh(_meshTransform._mesh.Matrix_VertToLocal, _meshTransform._mesh.MatrixHashCode);
                        rVert.SetMatrix_1_Static_Vert2Mesh(_meshTransform._mesh.Matrix_VertToLocal);

                        _computedVerts_Input[i]._posL = _renderVerts[i]._vertex._pos;
                        if (isRigging)
                        {
                            _computedVerts_Input[i]._posRigging = _calculatedStack.GetVertexRigging(i);
                        }
                        else
                        {
                            _computedVerts_Input[i]._posRigging = Vector2.zero;
                        }
                        if (isVertexLocal)
                        {
                            _computedVerts_Input[i]._calVertLocal = _calculatedStack.GetVertexLocalPos(i);
                        }
                        else
                        {
                            _computedVerts_Input[i]._calVertLocal = Vector2.zero;
                        }
                        if (isVertexWorld)
                        {
                            _computedVerts_Input[i]._calVertWorld = _calculatedStack.GetVertexWorldPos(i);
                        }
                        else
                        {
                            _computedVerts_Input[i]._calVertWorld = Vector2.zero;
                        }
                    }
                    Profiler.EndSample();

                    #region [미사용 코드]
                    //[ Compute Shader를 써보자 ]
                    //for (int i = 0; i < _renderVerts.Count; i++)
                    //{
                    //	rVert = _renderVerts[i];

                    //	//중복 처리 제거 코드를 리셋한다. (강제로 업데이트하기 위함)
                    //	if (isMatrixCalculateForce)
                    //	{
                    //		rVert.ResetMatrixHashCode();
                    //	}

                    //	rVert.ReadyToCalculate();

                    //	//단계별로 처리하자

                    //	//1) Pivot 위치 적용
                    //	rVert.SetMatrix_1_Static_Vert2Mesh(_meshTransform._mesh.Matrix_VertToLocal, _meshTransform._mesh.MatrixHashCode);


                    //	//추가) Rigging 정보를 넣자
                    //	if (isRigging)
                    //	{
                    //		rVert.SetRigging_0_LocalPosWeight(_calculatedStack.GetVertexRigging(i), _calculatedStack.GetRiggingWeight());
                    //	}

                    //	if (isVertexLocal)
                    //	{
                    //		//Calculate - Vertex Local Morph (Vec2)
                    //		rVert.SetMatrix_2_Calculate_VertLocal(_calculatedStack.GetVertexLocalPos(i));
                    //	}

                    //	rVert.SetMatrix_3_Transform_Mesh(WorldMatrix);

                    //	if (isVertexWorld)
                    //	{
                    //		//Calculate - Vertex World Morph (Vec2)
                    //		rVert.SetMatrix_4_Calculate_VertWorld(_calculatedStack.GetVertexWorldPos(i));
                    //	}
                    //}
                    #endregion


                    Profiler.BeginSample("4. Compute");
                    //apComputeShader.I.Compute_Editor_New(_computedVerts_Input, _computedVerts_Output, _renderVerts, _meshTransform._mesh.Matrix_VertToLocal, WorldMatrix, riggingWeight);
                    apComputeShader.I.AddRenderRequest(this,
                                                       _computedVerts_Input,
                                                       _renderVerts,
                                                       _meshTransform.
                                                       _mesh.Matrix_VertToLocal,
                                                       WorldMatrix,
                                                       riggingWeight);
                    Profiler.EndSample();
                }
                else
                {
                    for (int i = 0; i < _renderVerts.Count; i++)
                    {
                        rVert = _renderVerts[i];

                        //중복 처리 제거 코드를 리셋한다. (강제로 업데이트하기 위함)
                        //if (isMatrixCalculateForce)
                        //{
                        //	rVert.ResetMatrixHashCode();
                        //}

                        rVert.ReadyToCalculate();

                        //단계별로 처리하자



                        //1) Pivot 위치 적용
                        //rVert.SetMatrix_1_Static_Vert2Mesh(_meshTransform._mesh.Matrix_VertToLocal, _meshTransform._mesh.MatrixHashCode);
                        rVert.SetMatrix_1_Static_Vert2Mesh(_meshTransform._mesh.Matrix_VertToLocal);


                        #region [미사용 코드] 해시코드 사용 안한다.
                        //if (rVert.SetCalculateHashCode(_calculatedStack.CalculateHashCode))
                        //{
                        //	//추가) Rigging 정보를 넣자
                        //	if (isRigging)
                        //	{
                        //		rVert.SetRigging_0_LocalPosWeight(_calculatedStack.GetVertexRigging(i), _calculatedStack.GetRiggingWeight());
                        //	}

                        //	if (isVertexLocal)
                        //	{
                        //		//Calculate - Vertex Local Morph (Vec2)
                        //		rVert.SetMatrix_2_Calculate_VertLocal(_calculatedStack.GetVertexLocalPos(i));
                        //	}

                        //	rVert.SetMatrix_3_Transform_Mesh(WorldMatrix);

                        //	if (isVertexWorld)
                        //	{
                        //		//Calculate - Vertex World Morph (Vec2)
                        //		rVert.SetMatrix_4_Calculate_VertWorld(_calculatedStack.GetVertexWorldPos(i));
                        //	}
                        //}

                        #endregion

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

                        if (isVertexLocal)
                        {
                            //Calculate - Vertex Local Morph (Vec2)
                            rVert.SetMatrix_2_Calculate_VertLocal(_calculatedStack.GetVertexLocalPos(i));
                        }

                        rVert.SetMatrix_3_Transform_Mesh(WorldMatrix);

                        if (isVertexWorld)
                        {
                            //Calculate - Vertex World Morph (Vec2)
                            rVert.SetMatrix_4_Calculate_VertWorld(_calculatedStack.GetVertexWorldPos(i));
                        }

                        rVert.Calculate(tDelta);
                    }
                }
            }

            if (_childRenderUnits.Count > 0)
            {
                apRenderUnit childRenderUnit = null;
                for (int i = 0; i < _childRenderUnits.Count; i++)
                {
                    childRenderUnit = _childRenderUnits[i];

                    //childRenderUnit.UpdateToRenderVert(tDelta, isUpdateAlways, isMatrixCalculateForce, funcForceUpdate);
                    childRenderUnit.UpdateToRenderVert(tDelta, isUpdateAlways);
                }
            }
        }
示例#12
0
        public void DrawRenderUnit_ClippingParent_Renew(apRenderUnit renderUnit,
                                                        List <apTransform_Mesh.ClipMeshSet> childClippedSet,
                                                        RenderTexture externalRenderTexture = null)
        {
            //렌더링 순서
            //Parent - 기본
            //Parent - Mask
            //(For) Child - Clipped
            //Release RenderMask
            try
            {
                //0. 메시, 텍스쳐가 없을 때
                if (renderUnit == null || renderUnit._meshTransform == null || renderUnit._meshTransform._mesh == null)
                {
                    return;
                }

                if (renderUnit._renderVerts.Count == 0)
                {
                    return;
                }
                Color  textureColor = renderUnit._meshTransform._meshColor2X_Default;               //<<Default값
                apMesh mesh         = renderUnit._meshTransform._mesh;


                //if (mesh._textureData == null)
                if (mesh.LinkedTextureData == null)
                {
                    return;
                }

                int nClipMeshes = childClippedSet.Count;

                //렌더링 방식은 Mesh (with Color) 또는 Vertex / Outline이 있다.

                //1. Parent의 기본 렌더링을 하자
                //+2. Parent의 마스크를 렌더링하자
                if (mesh._indexBuffer.Count < 3)
                {
                    return;
                }

                apRenderVertex rVert0 = null, rVert1 = null, rVert2 = null;

                Color vertexChannelColor = Color.black;
                Color vColor0 = Color.black, vColor1 = Color.black, vColor2 = Color.black;

                Vector2 posGL_0 = Vector2.zero;
                Vector2 posGL_1 = Vector2.zero;
                Vector2 posGL_2 = Vector2.zero;

                Vector3 pos_0 = Vector3.zero;
                Vector3 pos_1 = Vector3.zero;
                Vector3 pos_2 = Vector3.zero;

                Vector2 uv_0 = Vector2.zero;
                Vector2 uv_1 = Vector2.zero;
                Vector2 uv_2 = Vector2.zero;



                RenderTexture.active = null;

                for (int iPass = 0; iPass < 2; iPass++)
                {
                    bool isRenderTexture = false;
                    if (iPass == 1)
                    {
                        isRenderTexture = true;
                    }

                    _matBatch.SetPass_Mask(textureColor, mesh.LinkedTextureData._image, 0.0f, renderUnit.ShaderType, isRenderTexture);
                    _matBatch.SetClippingSize(_glScreenClippingSize);


                    GL.Begin(GL.TRIANGLES);
                    //------------------------------------------
                    for (int i = 0; i < mesh._indexBuffer.Count; i += 3)
                    {
                        if (i + 2 >= mesh._indexBuffer.Count)
                        {
                            break;
                        }

                        if (mesh._indexBuffer[i + 0] >= mesh._vertexData.Count ||
                            mesh._indexBuffer[i + 1] >= mesh._vertexData.Count ||
                            mesh._indexBuffer[i + 2] >= mesh._vertexData.Count)
                        {
                            break;
                        }

                        rVert0 = renderUnit._renderVerts[mesh._indexBuffer[i + 0]];
                        rVert1 = renderUnit._renderVerts[mesh._indexBuffer[i + 1]];
                        rVert2 = renderUnit._renderVerts[mesh._indexBuffer[i + 2]];

                        vColor0 = Color.black;
                        vColor1 = Color.black;
                        vColor2 = Color.black;



                        posGL_0 = World2GL(rVert0._pos_World_NoMod);                        //<<Mod가 적용 안된걸로
                        posGL_1 = World2GL(rVert1._pos_World_NoMod);
                        posGL_2 = World2GL(rVert2._pos_World_NoMod);

                        pos_0.x = posGL_0.x;
                        pos_0.y = posGL_0.y;
                        pos_0.z = rVert0._vertex._zDepth * 0.5f;

                        pos_1.x = posGL_1.x;
                        pos_1.y = posGL_1.y;
                        pos_1.z = rVert1._vertex._zDepth * 0.5f;

                        pos_2.x = posGL_2.x;
                        pos_2.y = posGL_2.y;
                        pos_2.z = rVert2._vertex._zDepth * 0.5f;

                        uv_0 = mesh._vertexData[mesh._indexBuffer[i + 0]]._uv;
                        uv_1 = mesh._vertexData[mesh._indexBuffer[i + 1]]._uv;
                        uv_2 = mesh._vertexData[mesh._indexBuffer[i + 2]]._uv;


                        GL.Color(vColor0); GL.TexCoord(uv_0); GL.Vertex(pos_0);                         // 0
                        GL.Color(vColor1); GL.TexCoord(uv_1); GL.Vertex(pos_1);                         // 1
                        GL.Color(vColor2); GL.TexCoord(uv_2); GL.Vertex(pos_2);                         // 2

                        // Back Side
                        GL.Color(vColor2); GL.TexCoord(uv_2); GL.Vertex(pos_2);                         // 2
                        GL.Color(vColor1); GL.TexCoord(uv_1); GL.Vertex(pos_1);                         // 1
                        GL.Color(vColor0); GL.TexCoord(uv_0); GL.Vertex(pos_0);                         // 0
                    }



                    //------------------------------------------
                    GL.End();
                }

                if (externalRenderTexture == null)
                {
                    _matBatch.DeactiveRenderTexture();
                }
                else
                {
                    RenderTexture.active = externalRenderTexture;
                }



                //3. Child를 렌더링하자
                //for (int iClip = 0; iClip < 3; iClip++)
                for (int iClip = 0; iClip < nClipMeshes; iClip++)
                {
                    if (childClippedSet[iClip] == null || childClippedSet[iClip]._meshTransform == null)
                    {
                        continue;
                    }
                    apMesh       clipMesh       = childClippedSet[iClip]._meshTransform._mesh;
                    apRenderUnit clipRenderUnit = childClippedSet[iClip]._renderUnit;

                    if (clipMesh == null || clipRenderUnit == null)
                    {
                        continue;
                    }
                    if (clipRenderUnit._meshTransform == null)
                    {
                        continue;
                    }
                    if (!clipRenderUnit._isVisible)
                    {
                        continue;
                    }

                    if (clipMesh._indexBuffer.Count < 3)
                    {
                        continue;
                    }

                    _matBatch.SetPass_Clipped(clipRenderUnit._meshTransform._meshColor2X_Default,
                                              clipMesh.LinkedTextureData._image,
                                              0.0f,
                                              clipRenderUnit.ShaderType,
                                              renderUnit._meshTransform._meshColor2X_Default);

                    _matBatch.SetClippingSize(_glScreenClippingSize);

                    GL.Begin(GL.TRIANGLES);
                    //------------------------------------------
                    for (int i = 0; i < clipMesh._indexBuffer.Count; i += 3)
                    {
                        if (i + 2 >= clipMesh._indexBuffer.Count)
                        {
                            break;
                        }

                        if (clipMesh._indexBuffer[i + 0] >= clipMesh._vertexData.Count ||
                            clipMesh._indexBuffer[i + 1] >= clipMesh._vertexData.Count ||
                            clipMesh._indexBuffer[i + 2] >= clipMesh._vertexData.Count)
                        {
                            break;
                        }

                        rVert0 = clipRenderUnit._renderVerts[clipMesh._indexBuffer[i + 0]];
                        rVert1 = clipRenderUnit._renderVerts[clipMesh._indexBuffer[i + 1]];
                        rVert2 = clipRenderUnit._renderVerts[clipMesh._indexBuffer[i + 2]];


                        vColor0 = Color.black;
                        vColor1 = Color.black;
                        vColor2 = Color.black;



                        posGL_0 = World2GL(rVert0._pos_World_NoMod);                        //Mod 없는 걸로
                        posGL_1 = World2GL(rVert1._pos_World_NoMod);
                        posGL_2 = World2GL(rVert2._pos_World_NoMod);

                        pos_0.x = posGL_0.x;
                        pos_0.y = posGL_0.y;
                        pos_0.z = rVert0._vertex._zDepth * 0.5f;

                        pos_1.x = posGL_1.x;
                        pos_1.y = posGL_1.y;
                        pos_1.z = rVert1._vertex._zDepth * 0.5f;

                        pos_2.x = posGL_2.x;
                        pos_2.y = posGL_2.y;
                        pos_2.z = rVert2._vertex._zDepth * 0.5f;

                        uv_0 = clipMesh._vertexData[clipMesh._indexBuffer[i + 0]]._uv;
                        uv_1 = clipMesh._vertexData[clipMesh._indexBuffer[i + 1]]._uv;
                        uv_2 = clipMesh._vertexData[clipMesh._indexBuffer[i + 2]]._uv;


                        GL.Color(vColor0);      GL.TexCoord(uv_0);      GL.Vertex(pos_0);                         // 0
                        GL.Color(vColor1);      GL.TexCoord(uv_1);      GL.Vertex(pos_1);                         // 1
                        GL.Color(vColor2);      GL.TexCoord(uv_2);      GL.Vertex(pos_2);                         // 2

                        //Back Side
                        GL.Color(vColor2);      GL.TexCoord(uv_2);      GL.Vertex(pos_2);                         // 2
                        GL.Color(vColor1);      GL.TexCoord(uv_1);      GL.Vertex(pos_1);                         // 1
                        GL.Color(vColor0);      GL.TexCoord(uv_0);      GL.Vertex(pos_0);                         // 0
                    }
                    //------------------------------------------------
                    GL.End();
                }

                //사용했던 RenderTexture를 해제한다.
                _matBatch.ReleaseRenderTexture();
                //_matBatch.DeactiveRenderTexture();
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
        }
示例#13
0
        //--------------------------------------------------------------------------------------------------
        public void DrawRenderUnit(apRenderUnit renderUnit)
        {
            try
            {
                //0. 메시, 텍스쳐가 없을 때
                if (renderUnit == null || renderUnit._meshTransform == null || renderUnit._meshTransform._mesh == null)
                {
                    return;
                }

                if (renderUnit._renderVerts.Count == 0)
                {
                    return;
                }
                Color textureColor = renderUnit._meshTransform._meshColor2X_Default;                //<<Default값을 사용한다.


                apMesh mesh      = renderUnit._meshTransform._mesh;
                bool   isVisible = renderUnit._meshTransform._isVisible_Default;              //<<Default값을 사용

                //if (mesh._textureData == null)
                if (mesh.LinkedTextureData == null)
                {
                    return;
                }

                //미리 GL 좌표를 연산하고, 나중에 중복 연산(World -> GL)을 하지 않도록 하자
                apRenderVertex rVert = null;
                for (int i = 0; i < renderUnit._renderVerts.Count; i++)
                {
                    rVert         = renderUnit._renderVerts[i];
                    rVert._pos_GL = World2GL(rVert._pos_World_NoMod);                    //<<Mod 적용 안된걸로
                }



                //렌더링 방식은 Mesh (with Color) 또는 Vertex / Outline이 있다.

                //2. 메시를 렌더링하자
                if (mesh._indexBuffer.Count >= 3 && isVisible)
                {
                    //------------------------------------------
                    // Drawcall Batch를 했을때
                    // Debug.Log("Texture Color : " + textureColor);
                    Color color0 = Color.black, color1 = Color.black, color2 = Color.black;


                    _matBatch.SetPass_Texture_VColor(textureColor, mesh.LinkedTextureData._image, 0.0f, renderUnit.ShaderType);
                    _matBatch.SetClippingSize(_glScreenClippingSize);


                    GL.Begin(GL.TRIANGLES);
                    //------------------------------------------
                    //apVertex vert0, vert1, vert2;
                    apRenderVertex rVert0 = null, rVert1 = null, rVert2 = null;


                    Vector3 pos_0 = Vector3.zero;
                    Vector3 pos_1 = Vector3.zero;
                    Vector3 pos_2 = Vector3.zero;


                    Vector2 uv_0 = Vector2.zero;
                    Vector2 uv_1 = Vector2.zero;
                    Vector2 uv_2 = Vector2.zero;

                    for (int i = 0; i < mesh._indexBuffer.Count; i += 3)
                    {
                        if (i + 2 >= mesh._indexBuffer.Count)
                        {
                            break;
                        }

                        if (mesh._indexBuffer[i + 0] >= mesh._vertexData.Count ||
                            mesh._indexBuffer[i + 1] >= mesh._vertexData.Count ||
                            mesh._indexBuffer[i + 2] >= mesh._vertexData.Count)
                        {
                            break;
                        }

                        rVert0 = renderUnit._renderVerts[mesh._indexBuffer[i + 0]];
                        rVert1 = renderUnit._renderVerts[mesh._indexBuffer[i + 1]];
                        rVert2 = renderUnit._renderVerts[mesh._indexBuffer[i + 2]];

                        pos_0.x = rVert0._pos_GL.x;
                        pos_0.y = rVert0._pos_GL.y;
                        pos_0.z = rVert0._vertex._zDepth * 0.5f;

                        pos_1.x = rVert1._pos_GL.x;
                        pos_1.y = rVert1._pos_GL.y;
                        pos_1.z = rVert1._vertex._zDepth * 0.5f;

                        pos_2.x = rVert2._pos_GL.x;
                        pos_2.y = rVert2._pos_GL.y;
                        pos_2.z = rVert2._vertex._zDepth * 0.5f;


                        uv_0 = mesh._vertexData[mesh._indexBuffer[i + 0]]._uv;
                        uv_1 = mesh._vertexData[mesh._indexBuffer[i + 1]]._uv;
                        uv_2 = mesh._vertexData[mesh._indexBuffer[i + 2]]._uv;


                        ////------------------------------------------

                        GL.Color(color0); GL.TexCoord(uv_0); GL.Vertex(pos_0);                         // 0
                        GL.Color(color1); GL.TexCoord(uv_1); GL.Vertex(pos_1);                         // 1
                        GL.Color(color2); GL.TexCoord(uv_2); GL.Vertex(pos_2);                         // 2

                        // Back Side
                        GL.Color(color2); GL.TexCoord(uv_2); GL.Vertex(pos_2);                         // 2
                        GL.Color(color1); GL.TexCoord(uv_1); GL.Vertex(pos_1);                         // 1
                        GL.Color(color0); GL.TexCoord(uv_0); GL.Vertex(pos_0);                         // 0

                        ////------------------------------------------
                    }
                    GL.End();
                }



                //DrawText("<-[" + renderUnit.Name + "_" + renderUnit._debugID + "]", renderUnit.WorldMatrixWrap._pos + new Vector2(10.0f, 0.0f), 100, Color.yellow);
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
        }
        // 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가 아예 없군염
                    }
                }
            }
        }