Exemplo n.º 1
0
        public override bool Save(object target, string strParam)
        {
            base.Save(target, strParam);

            if (!(target is apModifiedVertexRig))
            {
                return(false);
            }

            apModifiedVertexRig vertRig = target as apModifiedVertexRig;

            if (vertRig == null)
            {
                return(false);
            }

            _weightPairs.Clear();
            for (int i = 0; i < vertRig._weightPairs.Count; i++)
            {
                apModifiedVertexRig.WeightPair srcWP = vertRig._weightPairs[i];
                _weightPairs.Add(new WeightPair(srcWP._bone, srcWP._meshGroup, srcWP._weight));
            }

            return(true);
        }
            // Bake
            //----------------------------------------------------------------
            public bool Bake(apModifiedVertexRig srcModVert)
            {
                //변경 : 8.2 유효한 Weight Pair만 전달하자
                List <apModifiedVertexRig.WeightPair> validSrcWeightPairs = new List <apModifiedVertexRig.WeightPair>();

                for (int i = 0; i < srcModVert._weightPairs.Count; i++)
                {
                    apModifiedVertexRig.WeightPair srcWeightPair = srcModVert._weightPairs[i];
                    if (srcWeightPair == null)
                    {
                        continue;
                    }
                    if (srcWeightPair._weight <= 0.00001f)
                    {
                        continue;
                        ;
                    }
                    validSrcWeightPairs.Add(srcWeightPair);
                }

                _weightPairs = new WeightPair[validSrcWeightPairs.Count];

                for (int i = 0; i < validSrcWeightPairs.Count; i++)
                {
                    apModifiedVertexRig.WeightPair srcWeightPair = validSrcWeightPairs[i];

                    WeightPair optWeightPair = new WeightPair();
                    optWeightPair.Bake(srcWeightPair);

                    _weightPairs[i] = optWeightPair;
                }

                //Normalize를 하자
                float totalWeight = 0.0f;

                for (int i = 0; i < _weightPairs.Length; i++)
                {
                    totalWeight += _weightPairs[i]._weight;
                }

                //Noamlize는 1 이상일 때에만
                //if (totalWeight > 0.0f)
                if (totalWeight > 1.0f)
                {
                    for (int i = 0; i < _weightPairs.Length; i++)
                    {
                        _weightPairs[i]._weight /= totalWeight;
                    }
                }

                return(true);
            }
Exemplo n.º 3
0
        public override bool Load(object targetObj)
        {
            apModifiedVertexRig vertRig = targetObj as apModifiedVertexRig;

            if (vertRig == null)
            {
                return(false);
            }

            //일단 값을 모두 초기화한다.
            for (int i = 0; i < vertRig._weightPairs.Count; i++)
            {
                vertRig._weightPairs[i]._weight = 0.0f;
            }

            //저장된 값을 넣어준다.
            for (int iSrc = 0; iSrc < _weightPairs.Count; iSrc++)
            {
                WeightPair src = _weightPairs[iSrc];
                if (src._bone == null || src._meshGroup == null)
                {
                    continue;
                }

                apModifiedVertexRig.WeightPair dstWeightPair = vertRig._weightPairs.Find(delegate(apModifiedVertexRig.WeightPair a)
                {
                    return(a._bone == src._bone);
                });

                if (dstWeightPair == null)
                {
                    apModifiedVertexRig.WeightPair newWP = new apModifiedVertexRig.WeightPair(src._bone);
                    newWP._weight = src._weight;
                    vertRig._weightPairs.Add(newWP);
                }
                else
                {
                    dstWeightPair._weight = src._weight;
                }
            }

            vertRig.CalculateTotalWeight();

            return(true);
        }
Exemplo n.º 4
0
            //ModVertRig > WeightPairData
            public void SetModVertRig(apModifiedVertexRig modVertRig)
            {
                //위치 저장 (Modifier 적용 없이)
                _posWorld = modVertRig._renderVertex._pos_World_NoMod;


                //WeightPair 리스트를 저장한다.
                if (_weightPairs == null)
                {
                    _weightPairs = new List <WeightPairData>();
                }
                _weightPairs.Clear();


                if (modVertRig._weightPairs.Count == 0)
                {
                    return;
                }

                float totalWeight = 0.0f;

                for (int iSrc = 0; iSrc < modVertRig._weightPairs.Count; iSrc++)
                {
                    apModifiedVertexRig.WeightPair srcWeightPair = modVertRig._weightPairs[iSrc];
                    if (srcWeightPair._bone == null)
                    {
                        continue;
                    }

                    totalWeight += srcWeightPair._weight;
                    _weightPairs.Add(new WeightPairData(srcWeightPair._bone, srcWeightPair._weight));
                }

                if (_weightPairs.Count > 0 && totalWeight > 0.0f)
                {
                    //Normalize를 하자
                    for (int i = 0; i < _weightPairs.Count; i++)
                    {
                        _weightPairs[i]._weight /= totalWeight;
                    }
                }

                //Debug.Log("Pos-Copy : " + _posWorld + " / Pairs : " + _weightPairs.Count);
            }
Exemplo n.º 5
0
            //저장된 값을 대상 ModVertRig에 복사한다.
            public void PasteToModVertRig(apMeshGroup keyMeshGroup, apModifiedVertexRig targetModVertRig)
            {
                if (targetModVertRig == null)
                {
                    return;
                }


                targetModVertRig._weightPairs.Clear();

                for (int iSrcPair = 0; iSrcPair < _weightPairs.Count; iSrcPair++)
                {
                    WeightPairData srcPair = _weightPairs[iSrcPair];
                    apModifiedVertexRig.WeightPair dstPair = new apModifiedVertexRig.WeightPair(srcPair._bone);
                    dstPair._meshGroup   = keyMeshGroup;
                    dstPair._meshGroupID = keyMeshGroup._uniqueID;
                    dstPair._weight      = srcPair._weight;

                    targetModVertRig._weightPairs.Add(dstPair);
                }
            }
Exemplo n.º 6
0
        public bool Bake(apModifiedVertexRig srcModVert, apOptMesh mesh, apPortrait portrait)
        {
            _vertexUniqueID = srcModVert._vertexUniqueID;
            _vertIndex      = srcModVert._vertIndex;
            _mesh           = mesh;

            _weightPairs = new OptWeightPair[srcModVert._weightPairs.Count];

            for (int i = 0; i < srcModVert._weightPairs.Count; i++)
            {
                apModifiedVertexRig.WeightPair srcWeightPair = srcModVert._weightPairs[i];
                OptWeightPair optWeightPair = new OptWeightPair(srcWeightPair);
                optWeightPair.Link(portrait);

                _weightPairs[i] = optWeightPair;
            }



            return(true);
        }
Exemplo n.º 7
0
 public OptWeightPair(apModifiedVertexRig.WeightPair srcWeightPair)
 {
     _boneID      = srcWeightPair._boneID;
     _meshGroupID = srcWeightPair._meshGroupID;
     _weight      = srcWeightPair._weight;
 }
Exemplo n.º 8
0
        public bool Bake(apModifiedVertexRig srcModVert, apOptMesh mesh, apPortrait portrait)
        {
            _vertexUniqueID = srcModVert._vertexUniqueID;
            _vertIndex      = srcModVert._vertIndex;
            _mesh           = mesh;

            //변경 : 8.2 유효한 Weight Pair만 전달하자
            List <apModifiedVertexRig.WeightPair> validSrcWeightPairs = new List <apModifiedVertexRig.WeightPair>();

            for (int i = 0; i < srcModVert._weightPairs.Count; i++)
            {
                apModifiedVertexRig.WeightPair srcWeightPair = srcModVert._weightPairs[i];
                if (srcWeightPair == null)
                {
                    continue;
                }
                if (srcWeightPair._weight <= 0.00001f)
                {
                    continue;;
                }
                validSrcWeightPairs.Add(srcWeightPair);
            }

            _weightPairs = new OptWeightPair[validSrcWeightPairs.Count];

            //변경 : 8.2 유효한 Vertex가 없어도 일단 Bake는 되어야 한다.
            //if(srcModVert._weightPairs.Count == 0)
            //{
            //	//Rig가 안된 Vertex가 있다.
            //	Debug.LogError("AnyPortrait : There is a vertex with no rigging data. The Rigging Modifier is not applied to this mesh [" + mesh.name + "]. Check the Rigging value.");
            //	return false;
            //}

            //for (int i = 0; i < srcModVert._weightPairs.Count; i++)
            for (int i = 0; i < validSrcWeightPairs.Count; i++)
            {
                //apModifiedVertexRig.WeightPair srcWeightPair = srcModVert._weightPairs[i];
                apModifiedVertexRig.WeightPair srcWeightPair = validSrcWeightPairs[i];

                //추가 : 유효한 Weight만 추가 > 이 코드가 버그를 발생시킨다.
                //if(srcWeightPair._weight <= 0.00001f)
                //{
                //	continue;
                //}
                OptWeightPair optWeightPair = new OptWeightPair(srcWeightPair);
                optWeightPair.Link(portrait);

                _weightPairs[i] = optWeightPair;
            }

            //변경 : 8.2 0개라도 Bake를 하는 것으로 변경
            //if(_weightPairs.Length == 0)
            //{
            //	//처리된 Pair가 없으면 false
            //	Debug.LogError("AnyPortrait : There is a vertex with no valid rigging data. The Rigging Modifier is not applied to this mesh [" + mesh.name + "]. Check the Rigging value.");
            //	return false;
            //}

            //추가 : Normalize를 하자
            float totalWeight = 0.0f;


            for (int i = 0; i < _weightPairs.Length; i++)
            {
                totalWeight += _weightPairs[i]._weight;
            }
            //Noamlize는 1 이상일 때에만
            //if (totalWeight > 0.0f)
            if (totalWeight > 1.0f)
            {
                //if(totalWeight > 1.0f)
                //{
                //	Debug.LogError("OPT Rigging Weight Normalize [" + totalWeight + "]");
                //}

                for (int i = 0; i < _weightPairs.Length; i++)
                {
                    //Debug.LogError("[" + i + "] : " + _weightPairs[i]._weight + " >> " + (_weightPairs[i]._weight / totalWeight));
                    _weightPairs[i]._weight /= totalWeight;
                }
            }
            //변경 8.2 : Weight 에러는 없다.
            //else
            //{
            //	//전체 Weight가 0이다?
            //	Debug.LogError("AnyPortrait : There is a vertex with a sum of Rigging values of zero. The Rigging Modifier is not applied to this mesh [" + mesh.name + "]. Check the Rigging value.");
            //	return false;
            //}



            return(true);
        }