Ejemplo n.º 1
0
        private void _頂点位置をリセットする()
        {
            foreach (int i in _movedVertex)
            {
                頂点 vertexData = _model.頂点リスト[i];
                _Buffermanager.入力頂点リスト[i].Position = new Vector4(vertexData.位置, 1f);
            }

            _movedVertex = new HashSet <uint>();
        }
Ejemplo n.º 2
0
        private void _頂点データを頂点レイアウトリストに追加する(頂点 頂点データ, List <CS_INPUT> 頂点レイアウトリスト)
        {
            var layout = new CS_INPUT()
            {
                Position   = new Vector4(頂点データ.位置, 1f),
                Normal     = 頂点データ.法線,
                UV         = 頂点データ.UV,
                Index      = (uint)頂点レイアウトリスト.Count, // 現在の要素数 = List<>内でのこの要素のインデックス番号
                EdgeWeight = 頂点データ.エッジ倍率,
                形方式        = (uint)頂点データ.ウェイト変形方式,
            };

            switch (頂点データ.ウェイト変形方式)
            {
            case  形方式.BDEF1:
            {
                var v = (BDEF1)頂点データ.ボーンウェイト;
                layout.BoneIndex1  = (uint)((v.boneReferenceIndex < 0) ? 0 : v.boneReferenceIndex);
                layout.BoneIndex2  = 0;
                layout.BoneIndex3  = 0;
                layout.BoneIndex4  = 0;
                layout.BoneWeight1 = (v.boneReferenceIndex < 0) ? 0.0f : 1.0f;
                layout.BoneWeight2 = 0.0f;
                layout.BoneWeight3 = 0.0f;
                layout.BoneWeight4 = 0.0f;
            }
            break;

            case  形方式.BDEF2:
            {
                var v = (BDEF2)頂点データ.ボーンウェイト;
                layout.BoneIndex1  = (uint)((v.Bone1ReferenceIndex < 0) ? 0 : v.Bone1ReferenceIndex);
                layout.BoneIndex2  = (uint)((v.Bone2ReferenceIndex < 0) ? 0 : v.Bone2ReferenceIndex);
                layout.BoneIndex3  = 0;
                layout.BoneIndex4  = 0;
                layout.BoneWeight1 = (v.Bone1ReferenceIndex < 0) ? 0.0f : v.Bone1Weight;
                layout.BoneWeight2 = (v.Bone2ReferenceIndex < 0) ? 0.0f : v.Bone2Weight;
                layout.BoneWeight3 = 0.0f;
                layout.BoneWeight4 = 0.0f;
            }
            break;

            case  形方式.SDEF:
            {
                var v = (SDEF)頂点データ.ボーンウェイト;
                layout.BoneIndex1  = (uint)((v.Bone1ReferenceIndex < 0) ? 0 : v.Bone1ReferenceIndex);
                layout.BoneIndex2  = (uint)((v.Bone2ReferenceIndex < 0) ? 0 : v.Bone2ReferenceIndex);
                layout.BoneIndex3  = 0;
                layout.BoneIndex4  = 0;
                layout.BoneWeight1 = (v.Bone1ReferenceIndex < 0) ? 0.0f : v.Bone1Weight;
                layout.BoneWeight2 = (v.Bone2ReferenceIndex < 0) ? 0.0f : v.Bone2Weight;
                layout.BoneWeight3 = 0.0f;
                layout.BoneWeight4 = 0.0f;
                layout.Sdef_C      = new Vector4(v.SDEF_C, 1f);
                layout.SdefR0      = v.SDEF_R0;
                layout.SdefR1      = v.SDEF_R1;
            }
            break;

            case  形方式.BDEF4:
            case  形方式.QDEF:
            {
                var   v         = (BDEF4)頂点データ.ボーンウェイト;
                float sumWeight = v.Weights.X + v.Weights.Y + v.Weights.Z + v.Weights.W;
                if (!(0.99999f < sumWeight && sumWeight < 1.00001f) && v.Weights.W == 0f)
                {
                    // sumWeight ≒ 1.0 かつ W = 0 なら、W にあまり全部を足す。
                    v.Weights.W = 1.0f - v.Weights.X - v.Weights.Y - v.Weights.Z;
                    sumWeight   = 1.0f;
                }
                layout.BoneIndex1  = (uint)((v.Bone1ReferenceIndex < 0) ? 0 : v.Bone1ReferenceIndex);
                layout.BoneIndex2  = (uint)((v.Bone2ReferenceIndex < 0) ? 0 : v.Bone2ReferenceIndex);
                layout.BoneIndex3  = (uint)((v.Bone3ReferenceIndex < 0) ? 0 : v.Bone3ReferenceIndex);
                layout.BoneIndex4  = (uint)((v.Bone4ReferenceIndex < 0) ? 0 : v.Bone4ReferenceIndex);
                layout.BoneWeight1 = (v.Bone1ReferenceIndex < 0) ? 0.0f : v.Weights.X / sumWeight;
                layout.BoneWeight2 = (v.Bone2ReferenceIndex < 0) ? 0.0f : v.Weights.Y / sumWeight;
                layout.BoneWeight3 = (v.Bone3ReferenceIndex < 0) ? 0.0f : v.Weights.Z / sumWeight;
                layout.BoneWeight4 = (v.Bone4ReferenceIndex < 0) ? 0.0f : v.Weights.W / sumWeight;
            }
            break;
            }

            頂点レイアウトリスト.Add((layout));
        }