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; }
private void initialize(BinaryReader i_reader) { DataReader reader = new DataReader(i_reader); PMD_Header pPMDHeader = new PMD_Header(); pPMDHeader.read(reader); if (!pPMDHeader.szMagic.Equals("PMD", StringComparison.CurrentCultureIgnoreCase)) { throw new MmdException(); } this._name = pPMDHeader.szName; // ----------------------------------------------------- // 頂点数取得 this._number_of_vertex = reader.readInt();// if (this._number_of_vertex < 0) { throw new MmdException(); } // 頂点配列をコピー 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]; PMD_Vertex tmp_pmd_vertex = new PMD_Vertex(); for (int i = 0; i < _number_of_vertex; i++) { tmp_pmd_vertex.read(reader); _position_array[i].setValue(tmp_pmd_vertex.vec3Pos); _normal_array[i].setValue(tmp_pmd_vertex.vec3Normal); _texture_uv[i].setValue(tmp_pmd_vertex.uvTex); this._skin_info_array[i] = new PmdSkinInfo(); this._skin_info_array[i].fWeight = tmp_pmd_vertex.cbWeight / 100.0f; this._skin_info_array[i].unBoneNo[0] = tmp_pmd_vertex.unBoneNo[0]; this._skin_info_array[i].unBoneNo[1] = tmp_pmd_vertex.unBoneNo[1]; } // ----------------------------------------------------- // 頂点インデックス数取得 short[] indices_array = createIndicesArray(reader); // ----------------------------------------------------- // マテリアル数取得 int number_of_materials = reader.readInt(); // マテリアル配列をコピー this._materials = new PmdMaterial[number_of_materials]; PMD_Material tmp_pmd_material = new PMD_Material(); int indices_ptr = 0; for (int i = 0; i < number_of_materials; i++) { tmp_pmd_material.read(reader); this._materials[i] = new PmdMaterial(); this._materials[i].unknown = tmp_pmd_material.unknown; this._materials[i].indices = new short[tmp_pmd_material.ulNumIndices]; System.Array.Copy(indices_array, indices_ptr, this._materials[i].indices, 0, tmp_pmd_material.ulNumIndices); indices_ptr += tmp_pmd_material.ulNumIndices; this._materials[i].col4Diffuse.setValue(tmp_pmd_material.col4Diffuse); this._materials[i].col4Specular.r = tmp_pmd_material.col3Specular.r; this._materials[i].col4Specular.g = tmp_pmd_material.col3Specular.g; this._materials[i].col4Specular.b = tmp_pmd_material.col3Specular.b; this._materials[i].col4Specular.a = 1.0f; this._materials[i].col4Ambient.r = tmp_pmd_material.col3Ambient.r; this._materials[i].col4Ambient.g = tmp_pmd_material.col3Ambient.g; this._materials[i].col4Ambient.b = tmp_pmd_material.col3Ambient.b; this._materials[i].col4Ambient.a = 1.0f; this._materials[i].fShininess = tmp_pmd_material.fShininess; this._materials[i].texture_name = tmp_pmd_material.szTextureFileName; if (this._materials[i].texture_name.Length < 1) { this._materials[i].texture_name = null; } } //Boneの読み出し this.m_pBoneArray = createBoneArray(reader); //IK配列の読み出し this.m_pIKArray = createIKArray(reader, this.m_pBoneArray); //Face配列の読み出し this.m_pFaceArray = createFaceArray(reader); return; }