public void SolveIK(PmdIK ik) { Vector3 target = ik.target.GetWorldPosition(); for (int i = 0; i < ik.niteration; i++) { bool solved = true; foreach (PmdNode node in ik.chain_nodes) { solved &= SolveIK(ik.effector, node, target); } if (solved) { break; } } }
public void Load(Stream source_stream) { BinaryReader reader = new BinaryReader(source_stream, System.Text.Encoding.Default); byte[] magic = reader.ReadBytes(3); if (magic[0] != (byte)'P' || magic[1] != (byte)'m' || magic[2] != (byte)'d') { throw new Exception("File is not Pmd"); } float version = reader.ReadSingle(); Debug.WriteLine("version:" + version); string model_name = reader.ReadCString(20); Debug.WriteLine("model_name:" + model_name); string comment = reader.ReadCString(256); Debug.WriteLine("comment:" + comment); int vertex_count = reader.ReadInt32(); Debug.WriteLine("vertex_count:" + vertex_count); vertices = new Vertex[vertex_count]; for (int i = 0; i < vertex_count; i++) { vertices[i] = new Vertex(); vertices[i].Read(reader); } int face_vertex_count = reader.ReadInt32(); Debug.WriteLine("face_vertex_count:" + face_vertex_count); indices = new ushort[face_vertex_count]; for (int i = 0; i < face_vertex_count; i++) { indices[i] = reader.ReadUInt16(); } int face_count = face_vertex_count / 3; Debug.WriteLine("face_count:" + face_count); int material_count = reader.ReadInt32(); Debug.WriteLine("material_count:" + material_count); materials = new PmdMaterial[material_count]; for (int i = 0; i < material_count; i++) { materials[i] = new PmdMaterial(i); materials[i].Read(reader); } int face_vertex_start = 0; for (int i = 0; i < material_count; i++) { face_vertex_start = materials[i].InjectFaceVertexStart(face_vertex_start); } ushort node_count = reader.ReadUInt16(); Debug.WriteLine("node_count:" + node_count); nodes = new PmdNode[node_count]; for (ushort i = 0; i < node_count; i++) { nodes[i] = new PmdNode(i); nodes[i].Read(reader); } for (ushort i = 0; i < node_count; i++) { nodes[i].ComputeOffsetMatrix(); } GenerateNodemapAndTree(); bone_matrices = new Matrix[node_count]; ushort ik_count = reader.ReadUInt16(); Debug.WriteLine("ik_count:" + ik_count); iks = new PmdIK[ik_count]; for (ushort i = 0; i < ik_count; i++) { iks[i] = new PmdIK(); iks[i].Read(reader); } UpdateNodeIKs(); ushort skin_count = reader.ReadUInt16(); Debug.WriteLine("skin_count:" + skin_count); skins = new PmdSkin[skin_count]; for (ushort i = 0; i < skin_count; i++) { skins[i] = new PmdSkin(); skins[i].Read(reader); } for (ushort i = 1; i < skin_count; i++) { skins[i].Absolutize(skins[0]); } }