コード例 #1
0
        // (ベクトル1→ベクトル2)にフィットするような剛体を生成
        public void MakeBodyFromTwoVector(string bone_name, MmdVector3 v1, MmdVector3 v2)
        {
            PMD_RigidBody rigidbody = new PMD_RigidBody();

            rigidbody.rigidbody_name = bone_name; // 諸データ:名称 // 頭
            rigidbody.rigidbody_rel_bone_index = GetBoneIDByName(bone_name); // 諸データ:関連ボーン番号 // 03 00 == 3 // 頭
 
            float x1 = v1.x;
            float y1 = v1.y;
            float z1 = v1.z;
            float x2 = v2.x;
            float y2 = v2.y;
            float z2 = v2.z;
            double L = Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1));
            rigidbody.pos_pos.x = (x1 + x2) / 2.0f - x1; // 位置:位置(x, y, z)
            rigidbody.pos_pos.y = (y1 + y2) / 2.0f - y1; // 位置:位置(x, y, z)
            rigidbody.pos_pos.z = (z1 + z2) / 2.0f - z1; // 位置:位置(x, y, z)
            if (y1 >= y2) rigidbody.pos_rot.x = (float)Math.Asin((z1 - z2) / L); // 位置:回転(rad(x), rad(y), rad(z))
            else rigidbody.pos_rot.x = (float)Math.Asin((z2 - z1) / L);
            if (y1 >= y2) rigidbody.pos_rot.z = (float)Math.Asin(-(x1 - x2) / L); // 位置:回転(rad(x), rad(y), rad(z))
            else rigidbody.pos_rot.z = (float)Math.Asin(-(x2 - x1) / L);

            rigidbody.rigidbody_group_index = 0; // 諸データ:グループ // 00
            rigidbody.rigidbody_group_target = -1; // 諸データ:グループ:対象 // 0xFFFFとの差 // 38 FE
            rigidbody.shape_type = 2; // 形状:タイプ(0:球、1:箱、2:カプセル) // 00 // 球
            rigidbody.shape_w = 0.4f; // 形状:半径(幅) // CD CC CC 3F // 1.6
            rigidbody.shape_h = (float)(L * 0.8); // 形状:高さ // CD CC CC 3D // 0.1

            rigidbody.rigidbody_weight = 0.5f; // 諸データ:質量 // 00 00 80 3F // 1.0
            rigidbody.rigidbody_pos_dim = 0.5f; // 諸データ:移動減 // 00 00 00 00
            rigidbody.rigidbody_rot_dim = 0.5f; // 諸データ:回転減 // 00 00 00 00
            rigidbody.rigidbody_recoil = 0.0f; // 諸データ:反発力 // 00 00 00 00
            rigidbody.rigidbody_friction = 0.0f; // 諸データ:摩擦力 // 00 00 00 00
            rigidbody.rigidbody_type = 0; // 諸データ:タイプ(0:Bone追従、1:物理演算、2:物理演算(Bone位置合せ)) // 00 // Bone追従

            body_list.Add(rigidbody);
        }
コード例 #2
0
        // 指定したボーン位置に合わせた剛体を生成
        public void MakeBodyFromBoneEnd(int bone_num)
        {
            PMD_RigidBody rigidbody = new PMD_RigidBody();

            rigidbody.rigidbody_name = bone_list[bone_num].szName; // 諸データ:名称 // 頭
            rigidbody.rigidbody_rel_bone_index = bone_num; // 諸データ:関連ボーン番号 // 03 00 == 3 // 頭
            rigidbody.pos_pos.x = 0.0f;
            rigidbody.pos_pos.y = 0.0f;
            rigidbody.pos_pos.z = 0.0f;

            rigidbody.rigidbody_group_index = 0; // 諸データ:グループ // 00
            rigidbody.rigidbody_group_target = -1; // 諸データ:グループ:対象 // 0xFFFFとの差 // 38 FE
            rigidbody.shape_type = 0; // 形状:タイプ(0:球、1:箱、2:カプセル) // 00 // 球
            rigidbody.shape_w = 0.4f; // 形状:半径(幅) // CD CC CC 3F // 1.6

            rigidbody.rigidbody_weight = 0.5f; // 諸データ:質量 // 00 00 80 3F // 1.0
            rigidbody.rigidbody_pos_dim = 0.5f; // 諸データ:移動減 // 00 00 00 00
            rigidbody.rigidbody_rot_dim = 0.5f; // 諸データ:回転減 // 00 00 00 00
            rigidbody.rigidbody_recoil = 0.0f; // 諸データ:反発力 // 00 00 00 00
            rigidbody.rigidbody_friction = 0.0f; // 諸データ:摩擦力 // 00 00 00 00
            rigidbody.rigidbody_type = 0; // 諸データ:タイプ(0:Bone追従、1:物理演算、2:物理演算(Bone位置合せ)) // 00 // Bone追従

            body_list.Add(rigidbody);
        }
コード例 #3
0
        public void ReadPmdFile(BinaryReader i_reader)
        {
            DataReader reader = new DataReader(i_reader);

            // -----------------------------------------------------
            // ヘッダー情報取得
            pmd_header = new PMD_Header();
            pmd_header.read(reader);
            if (!pmd_header.szMagic.Equals("PMD", StringComparison.CurrentCultureIgnoreCase))
            {
                throw new MmdException();
            }

            // -----------------------------------------------------
            // 頂点数取得
            number_of_vertex = reader.readInt();//
            if (number_of_vertex < 0)
            {
                throw new MmdException();
            }

            // 頂点配列取得
            pmd_vertex = new PMD_Vertex[number_of_vertex];

            for (int i = 0; i < number_of_vertex; i++)
            {
                pmd_vertex[i] = new PMD_Vertex();
                pmd_vertex[i].read(reader);
            }

            // -----------------------------------------------------
            // 頂点インデックス数取得
            number_of_indices = reader.readInt();

            // 頂点インデックス配列取得
            indices_array = new short[number_of_indices];
            for (int i = 0; i < number_of_indices; i++)
            {
                indices_array[i] = reader.readShort();
            }

            // -----------------------------------------------------
            // マテリアル数取得
            number_of_materials = reader.readInt();

            // マテリアル配列取得
            pmd_material = new PMD_Material[number_of_materials];
            for (int i = 0; i < number_of_materials; i++)
            {
                pmd_material[i] = new PMD_Material();
                pmd_material[i].read(reader);
            }

            // -----------------------------------------------------
            // Bone数取得
            number_of_bone = reader.readShort();

            // Bone配列取得
            pmd_bone = new PMD_Bone[number_of_bone];
            for (int i = 0; i < number_of_bone; i++)
            {
                pmd_bone[i] = new PMD_Bone();
                pmd_bone[i].read(reader);
            }

            // ボーンIDを名前に置き換え
            // Bone
            foreach (PMD_Bone bone in pmd_bone)
            {
                if (bone.nParentNo <= -1)
                {
                    bone.ParentName = null;
                }
                else
                {
                    bone.ParentName = pmd_bone[bone.nParentNo].szName;
                }
                if (bone.nChildNo <= 0)
                {
                    bone.ChildName = null;
                }
                else
                {
                    bone.ChildName = pmd_bone[bone.nChildNo].szName;
                }
                if (bone.unIKTarget <= 0)
                {
                    bone.IKTargetName = null;
                }
                else
                {
                    bone.IKTargetName = pmd_bone[bone.unIKTarget].szName;
                }
            }
            // Vertex
            foreach (PMD_Vertex vertex in pmd_vertex)
            {
                if (vertex.unBoneNo[0] <= -1)
                {
                    vertex.unBoneName[0] = null;
                }
                else
                {
                    vertex.unBoneName[0] = pmd_bone[vertex.unBoneNo[0]].szName;
                }
                if (vertex.unBoneNo[1] <= -1)
                {
                    vertex.unBoneName[1] = null;
                }
                else
                {
                    vertex.unBoneName[1] = pmd_bone[vertex.unBoneNo[1]].szName;
                }
            }

            // -----------------------------------------------------
            // IK配列数取得
            number_of_ik = reader.readShort();

            // IK配列取得
            pmd_ik = new PMD_IK[number_of_ik];
            if (number_of_ik > 0)
            {
                for (int i = 0; i < number_of_ik; i++)
                {
                    pmd_ik[i] = new PMD_IK();
                    pmd_ik[i].read(reader);
                }
            }
            // ボーンIDを名前に置き換え
            foreach (PMD_IK ik in pmd_ik)
            {
                if (ik.nTargetNo <= -1)
                {
                    ik.nTargetName = null;
                }
                else
                {
                    ik.nTargetName = pmd_bone[ik.nTargetNo].szName;
                }
                if (ik.nEffNo <= -1)
                {
                    ik.nEffName = null;
                }
                else
                {
                    ik.nEffName = pmd_bone[ik.nEffNo].szName;
                }

                for (int i = 0; i < ik.cbNumLink; i++)
                {
                    if (ik.punLinkNo[i] <= -1)
                    {
                        ik.punLinkName[i] = null;
                    }
                    else
                    {
                        ik.punLinkName[i] = pmd_bone[ik.punLinkNo[i]].szName;
                    }
                }
            }

            // -----------------------------------------------------
            // Face数取得
            number_of_face = reader.readShort();

            // Face配列取得
            pmd_face = new PMD_FACE[number_of_face];
            if (number_of_face > 0)
            {
                for (int i = 0; i < number_of_face; i++)
                {
                    pmd_face[i] = new PMD_FACE();
                    pmd_face[i].read(reader);
                }
            }

            // -----------------------------------------------------
            // 表情枠
            // -----------------------------------------------------
            // 表情枠に表示する表情数
            skin_disp_count = reader.readByte();

            // 表情番号
            skin_index = new int[skin_disp_count];
            if (skin_disp_count > 0)
            {
                for (int i = 0; i < skin_disp_count; i++)
                {
                    skin_index[i] = reader.readShort();
                }
            }

            // -----------------------------------------------------
            // ボーン枠
            // -----------------------------------------------------
            // ボーン枠用の枠名数
            bone_disp_name_count = reader.readByte();

            // 枠名(50Bytes/枠)
            disp_name = new string[bone_disp_name_count];
            if (bone_disp_name_count > 0)
            {
                for (int i = 0; i < bone_disp_name_count; i++)
                {
                    disp_name[i] = reader.readAscii(50);
                }
            }

            // -----------------------------------------------------
            // ボーン枠に表示するボーン
            // -----------------------------------------------------
            // ボーン枠に表示するボーン数
            bone_disp_count = reader.readInt();

            // 枠用ボーンデータ (3Bytes/bone)
            bone_disp = new PMD_BoneDisp[bone_disp_count];
            if (bone_disp_count > 0)
            {
                for (int i = 0; i < bone_disp_count; i++)
                {
                    bone_disp[i] = new PMD_BoneDisp();
                    bone_disp[i].read(reader);
                }
            }

            // ボーンIDを名前に置き換え
            for (int i = 0; i < bone_disp.Length; i++)
            {
                bone_disp[i].bone_name = pmd_bone[bone_disp[i].bone_index].szName;
            }

            // -----------------------------------------------------
            // 英名対応(0:英名対応なし, 1:英名対応あり)
            // -----------------------------------------------------
            english_name_compatibility = reader.readByte();

            if (english_name_compatibility == 1)
            {
                model_name_eg = reader.readAscii(20);  // モデル名(英語)
                comment_eg    = reader.readAscii(256); // コメント(英語)

                // -----------------------------------------------------
                // ボーン名(英語)
                // -----------------------------------------------------
                bone_name_eg = new string[number_of_bone];
                if (number_of_bone > 0)
                {
                    for (int i = 0; i < number_of_bone; i++)
                    {
                        bone_name_eg[i] = reader.readAscii(20);
                    }
                }

                // -----------------------------------------------------
                // 表情名(英語)
                // -----------------------------------------------------
                skin_name_eg = new string[number_of_face - 1];
                if (number_of_face - 1 > 0)
                {
                    for (int i = 0; i < number_of_face - 1; i++)
                    {
                        skin_name_eg[i] = reader.readAscii(20);
                    }
                }

                // -----------------------------------------------------
                // 枠名(英語)
                // -----------------------------------------------------
                disp_name_eg = new string[bone_disp_name_count];
                if (bone_disp_name_count > 0)
                {
                    for (int i = 0; i < bone_disp_name_count; i++)
                    {
                        disp_name_eg[i] = reader.readAscii(50);
                    }
                }
            }

            // -----------------------------------------------------
            // トゥーンテクスチャファイル名
            // -----------------------------------------------------
            toon_file_name = new string[10];
            for (int i = 0; i < 10; i++)
            {
                toon_file_name[i] = reader.readAscii(100);
            }

            // -----------------------------------------------------
            // 剛体
            // -----------------------------------------------------
            // 剛体数
            rigidbody_count = reader.readInt();

            // 剛体データ(83Bytes/rigidbody)
            rigidbody = new PMD_RigidBody[rigidbody_count];
            if (rigidbody_count > 0)
            {
                for (int i = 0; i < rigidbody_count; i++)
                {
                    rigidbody[i] = new PMD_RigidBody();
                    rigidbody[i].read(reader);
                }
            }

            // -----------------------------------------------------
            // ジョイント
            // -----------------------------------------------------
            // ジョイント数
            joint_count = reader.readInt();

            // ジョイントデータ(124Bytes/joint)
            joint = new PMD_Joint[joint_count];
            if (joint_count > 0)
            {
                for (int i = 0; i < joint_count; i++)
                {
                    joint[i] = new PMD_Joint();
                    joint[i].read(reader);
                }
            }

            return;
        }