public float getDistanceBoneToVertex(IPEBone bone, IPEVertex vertex) { if (bone.To != -1 && bone.To != 0) { V3 from = (V3)bone.Position; V3 to = (V3)this.PMD.Bone[bone.To].Position; V3 v = (V3)vertex.Position; float d1, d2, d3; d1 = (v - from).Length(); d2 = (v - to).Length(); V3 line = to - from; V3 dif = v - from; if (line.Length() > 0.00001f) { d3 = (Cross(line, dif)).Length() / line.Length(); } else { d3 = 100000f; } if (line.Length() > 0) { float difDot = Dot(line, dif) / line.Length(); //垂線の足がボーン上 if (difDot > 0 && difDot < line.Length()) { return(Math.Min(d1, Math.Min(d2, d3))); } } return(Math.Min(d1, d2)); } else { V3 dif = (V3)((V3)vertex.Position - (V3)bone.Position); return(dif.Length()); } }