Example #1
0
        /// <summary>
        /// メッシュデータの指定インデクスの選択情報を取得する
        /// </summary>
        /// <param name="meshData"></param>
        /// <param name="vindex"></param>
        /// <returns></returns>
        private int GetSelection(MeshData meshData, int vindex, Dictionary <int, List <uint> > dict, List <MeshData> childMeshDataList, List <Dictionary <ulong, int> > hashList)
        {
            int data = Invalid;

            // セレクションデータ読み込み
            if (meshData != null && meshData.ChildCount > 0)
            {
                // 親頂点に影響する子頂点情報から取得
                if (dict.ContainsKey(vindex))
                {
                    foreach (var pack in dict[vindex])
                    {
                        int cmindex = DataUtility.Unpack16Hi(pack);
                        int cvindex = DataUtility.Unpack16Low(pack);

                        if (cmindex < selectionList.Count && cvindex < selectionList[cmindex].selectData.Count)
                        {
                            // 頂点ハッシュがある場合はハッシュからインデックスを取得する
                            // 現在メッシュの頂点ハッシュ
                            ulong vhash = 0;
                            if (childMeshDataList != null && cmindex < childMeshDataList.Count)
                            {
                                var cmdata = childMeshDataList[cmindex];
                                if (cmdata != null && cvindex < cmdata.VertexHashCount)
                                {
                                    vhash = cmdata.vertexHashList[cvindex];
                                }
                            }

                            // セレクションデータに頂点ハッシュが記録されているならば照合する
                            if (vhash != 0 && cmindex < hashList.Count)
                            {
                                if (hashList[cmindex].ContainsKey(vhash))
                                {
                                    // ハッシュ値に紐づく頂点ペイントデータに入れ替える
                                    cvindex = hashList[cmindex][vhash];
                                }
                            }

                            data = Mathf.Max(selectionList[cmindex].selectData[cvindex], data);
                        }
                    }
                }
            }
            else
            {
                // そのまま
                int dindex = 0;
                if (dindex < selectionList.Count)
                {
                    if (vindex < selectionList[dindex].selectData.Count)
                    {
                        data = selectionList[dindex].selectData[vindex];
                    }
                }
            }

            return(data);
        }
            // 頂点ごと
            public void Execute(int vindex)
            {
                uint flag = renderVertexFlagList[vindex];

                // 使用頂点のみ
                if ((flag & 0xffff0000) == 0)
                {
                    return;
                }

                // レンダーメッシュインデックス
                int rmindex = DataUtility.Unpack16Low(flag) - 1; // (-1)するので注意!
                var r_minfo = renderMeshInfoList[rmindex];

                if (r_minfo.InUse() == false)
                {
                    return;
                }
                bool calcNormal  = r_minfo.IsFlag(PhysicsManagerMeshData.Meshflag_CalcNormal);
                bool calcTangent = r_minfo.IsFlag(PhysicsManagerMeshData.Meshflag_CalcTangent);

                // レンダラーのローカル座標系に変換する
                int        tindex = r_minfo.transformIndex;
                var        tpos   = transformPosList[tindex];
                var        trot   = transformRotList[tindex];
                var        tscl   = transformSclList[tindex];
                quaternion itrot  = math.inverse(trot);

                // レンダラースケール
                float  scaleRatio     = r_minfo.baseScale > 0.0f ? math.length(tscl) / r_minfo.baseScale : 1.0f;
                float3 scaleDirection = math.sign(tscl);

                // ローカル頂点インデックス
                int i = vindex - r_minfo.vertexChunk.startIndex;

                // ローカル変換
                CollectionVertex(
                    ref r_minfo,
                    ref sharedChildVertexInfoList,
                    ref sharedChildVertexWeightList,
                    ref virtualPosList,
                    ref virtualRotList,
                    ref tpos,
                    ref trot,
                    ref tscl,
                    ref itrot,
                    scaleRatio,
                    ref scaleDirection,
                    calcNormal,
                    calcTangent,
                    vindex,
                    i,
                    flag,
                    ref renderPosList,
                    ref renderNormalList,
                    ref renderTangentList
                    );
            }
Example #3
0
        /// <summary>
        /// メッシュ頂点の選択データを設定する
        /// </summary>
        /// <param name="meshData"></param>
        /// <param name="selects"></param>
        public void SetSelectionData(MeshData meshData, List <int> selects, List <MeshData> childMeshDataList)
        {
            // 選択データ初期化
            selectionList.Clear();
            if (meshData != null && meshData.ChildCount > 0)
            {
                for (int i = 0; i < meshData.ChildCount; i++)
                {
                    var dsel  = new DeformerSelection();
                    int cvcnt = meshData.childDataList[i].VertexCount;
                    for (int j = 0; j < cvcnt; j++)
                    {
                        dsel.selectData.Add(Invalid);
                        dsel.vertexHashList.Add(0); // ハッシュ0=無効
                    }

                    selectionList.Add(dsel);
                }
            }
            else
            {
                // そのまま
                var dsel  = new DeformerSelection();
                int cvcnt = selects.Count;
                for (int j = 0; j < cvcnt; j++)
                {
                    dsel.selectData.Add(Invalid);
                    dsel.vertexHashList.Add(0); // ハッシュ0=無効
                }

                selectionList.Add(dsel);
            }

            // 選択データに追加
            for (int i = 0; i < selects.Count; i++)
            {
                int data = selects[i];
                if (meshData != null && meshData.ChildCount > 0)
                {
                    // 親頂点に影響する子頂点情報
                    Dictionary <int, List <uint> > dict = meshData.GetVirtualToChildVertexDict();

                    // 親頂点に影響する子頂点に記録
                    if (dict.ContainsKey(i))
                    {
                        foreach (var pack in dict[i])
                        {
                            int cmindex = DataUtility.Unpack16Hi(pack);
                            int cvindex = DataUtility.Unpack16Low(pack);

                            selectionList[cmindex].selectData[cvindex] = data;

                            // 頂点ハッシュも記録
                            if (cmindex < childMeshDataList.Count)
                            {
                                var cmdata = childMeshDataList[cmindex];
                                if (cmdata != null && cvindex < cmdata.VertexHashCount)
                                {
                                    selectionList[cmindex].vertexHashList[cvindex] = cmdata.vertexHashList[cvindex];
                                }
                            }
                        }
                    }
                }
                else
                {
                    // そのまま
                    selectionList[0].selectData[i] = data;
                }
            }

            // データハッシュ設定
            CreateVerifyData();
        }