Beispiel #1
0
        public MmdPmdModel(BinaryReader i_reader)
        {
            PmdFileData pmd = new PmdFileData(i_reader);

            initialize(pmd);
            return;
        }
Beispiel #2
0
        public MmdPmdModel(Stream i_stream)
        {
            PmdFileData pmd = new PmdFileData(i_stream);

            initialize(pmd);
            return;
        }
Beispiel #3
0
        // 名前からボーンIDを得る
        public static int GetBoneIDFromName(PmdFileData pmd, string name)
        {
            for (int i = 0; i < pmd.pmd_bone.Length; i++)
            {
                if (pmd.pmd_bone[i].szName == name)
                {
                    return(i);
                }
            }

            return(-1);
        }
Beispiel #4
0
        private void initialize(PmdFileData pmd)
        {
            // -----------------------------------------------------
            // モデル名をコピー
            this._name = pmd.pmd_header.szName;

            // -----------------------------------------------------
            // 頂点数をコピー
            this._number_of_vertex = pmd.number_of_vertex;

            // 頂点配列をコピー
            this._position_array  = MmdVector3.createArray(this._number_of_vertex);
            this._normal_array    = MmdVector3.createArray(this._number_of_vertex);
            this._texture_uv      = MmdTexUV.createArray(this._number_of_vertex);
            this._skin_info_array = new PmdSkinInfo[this._number_of_vertex];

            for (int i = 0; i < this._number_of_vertex; i++)
            {
                _position_array[i].setValue(pmd.pmd_vertex[i].vec3Pos);
                _normal_array[i].setValue(pmd.pmd_vertex[i].vec3Normal);
                _texture_uv[i].setValue(pmd.pmd_vertex[i].uvTex);

                this._skin_info_array[i]             = new PmdSkinInfo();
                this._skin_info_array[i].fWeight     = pmd.pmd_vertex[i].cbWeight / 100.0f;
                this._skin_info_array[i].unBoneNo[0] = pmd.pmd_vertex[i].unBoneNo[0];
                this._skin_info_array[i].unBoneNo[1] = pmd.pmd_vertex[i].unBoneNo[1];
            }

            // -----------------------------------------------------
            // マテリアル配列をコピー
            this._materials = new PmdMaterial[pmd.number_of_materials];

            int indices_ptr = 0;

            for (int i = 0; i < pmd.number_of_materials; i++)
            {
                this._materials[i]            = new PmdMaterial();
                this._materials[i].toon_index = pmd.pmd_material[i].toon_index;
                this._materials[i].edge_flag  = pmd.pmd_material[i].edge_flag;

                this._materials[i].indices = new short[pmd.pmd_material[i].ulNumIndices];
                System.Array.Copy(pmd.indices_array, indices_ptr, this._materials[i].indices, 0, pmd.pmd_material[i].ulNumIndices);
                indices_ptr += pmd.pmd_material[i].ulNumIndices;

                this._materials[i].col4Diffuse.setValue(pmd.pmd_material[i].col4Diffuse);

                this._materials[i].col4Specular.r = pmd.pmd_material[i].col3Specular.r;
                this._materials[i].col4Specular.g = pmd.pmd_material[i].col3Specular.g;
                this._materials[i].col4Specular.b = pmd.pmd_material[i].col3Specular.b;
                this._materials[i].col4Specular.a = 1.0f;

                this._materials[i].col4Ambient.r = pmd.pmd_material[i].col3Ambient.r;
                this._materials[i].col4Ambient.g = pmd.pmd_material[i].col3Ambient.g;
                this._materials[i].col4Ambient.b = pmd.pmd_material[i].col3Ambient.b;
                this._materials[i].col4Ambient.a = 1.0f;

                this._materials[i].fShininess = pmd.pmd_material[i].fShininess;

                this._materials[i].texture_name = pmd.pmd_material[i].szTextureFileName;
                if (this._materials[i].texture_name.Length < 1)
                {
                    this._materials[i].texture_name = null;
                }
            }

            // -----------------------------------------------------
            // Bone配列のコピー
            this.m_pBoneArray = new PmdBone[pmd.number_of_bone];
            for (int i = 0; i < pmd.number_of_bone; i++)
            {
                //ボーンの親子関係を一緒に読みだすので。
                this.m_pBoneArray[i] = new PmdBone(pmd.pmd_bone[i], this.m_pBoneArray);
            }
            for (int i = 0; i < pmd.number_of_bone; i++)
            {
                this.m_pBoneArray[i].recalcOffset();
            }

            // -----------------------------------------------------
            // IK配列のコピー
            this.m_pIKArray = new PmdIK[pmd.number_of_ik];
            // IK配列を作成
            if (pmd.number_of_ik > 0)
            {
                for (int i = 0; i < pmd.number_of_ik; i++)
                {
                    this.m_pIKArray[i] = new PmdIK(pmd.pmd_ik[i], this.m_pBoneArray);
                }
                System.Array.Sort <PmdIK>(this.m_pIKArray, new DataComparator());
            }

            // -----------------------------------------------------
            // Face配列のコピー
            if (pmd.number_of_face > 0)
            {
                this.m_pFaceArray = new PmdFace[pmd.number_of_face];
                for (int i = 0; i < pmd.number_of_face; i++)
                {
                    this.m_pFaceArray[i] = new PmdFace(pmd.pmd_face[i], this.m_pFaceArray[0]);
                }
            }

            return;
        }
Beispiel #5
0
 public MmdPmdModel(PmdFileData pmd)
 {
     initialize(pmd);
     return;
 }