private void SortFlamoNo() { for (int i = 0; i < mVmdCameras.Length - 1; i++) { for (int j = 0; j < mVmdCameras.Length - 1 - i; j++) { if (mVmdCameras[j].FlameNo > mVmdCameras[j + 1].FlameNo) //从大到小排序就用"<"号;反之用">"号 { VMD_CAMERA temp = mVmdCameras[j]; mVmdCameras[j] = mVmdCameras[j + 1]; mVmdCameras[j + 1] = temp; } } } }
public bool Load(string sFile) { byte[] buffer = null; try { using (var fs = new FileStream(sFile, FileMode.Open, FileAccess.Read)) { buffer = new byte[fs.Length]; fs.Read(buffer, 0, buffer.Length); } } catch { return(false); } finally { } int nPtr = 0, i = 0, nLoop = 0, j = 0; // VMD_HEADER nLoop = 30; for (i = 0; i < nLoop; i++) { clsHeader.VmdHeader[i] = buffer[nPtr + i]; if (buffer[nPtr + i] == '\0') { break; } } clsHeader.sVmdHeader = Encoding.GetEncoding("shift_jis").GetString(clsHeader.VmdHeader, 0, i); nPtr += nLoop; nLoop = 20; for (i = 0; i < nLoop; i++) { clsHeader.VmdModelName[i] = buffer[nPtr + i]; if (buffer[nPtr + i] == '\0') { break; } } clsHeader.sVmdModelName = Encoding.GetEncoding("shift_jis").GetString(clsHeader.VmdModelName, 0, i); nPtr += nLoop; // Motion nLoop = 4; uiMotionCount = BitConverter.ToUInt32(buffer, nPtr); nPtr += nLoop; if (uiMotionCount > 0) { clsMotion = new VMD_MOTION[uiMotionCount]; for (i = 0; i < (int)uiMotionCount; i++) { clsMotion[i] = new VMD_MOTION(); nLoop = 15; for (j = 0; j < nLoop; j++) { clsMotion[i].BoneName[j] = buffer[nPtr + j]; if (buffer[nPtr + j] == '\0') { break; } } clsMotion[i].sBoneName = Encoding.GetEncoding("shift_jis").GetString(clsMotion[i].BoneName, 0, j); nPtr += nLoop; nLoop = 4; clsMotion[i].FrameNo = BitConverter.ToUInt32(buffer, nPtr); nPtr += nLoop; nLoop = 4; clsMotion[i].Location[0] = BitConverter.ToSingle(buffer, nPtr); nPtr += nLoop; nLoop = 4; clsMotion[i].Location[1] = BitConverter.ToSingle(buffer, nPtr); nPtr += nLoop; nLoop = 4; clsMotion[i].Location[2] = BitConverter.ToSingle(buffer, nPtr); nPtr += nLoop; nLoop = 4; clsMotion[i].Rotatation[0] = BitConverter.ToSingle(buffer, nPtr); nPtr += nLoop; nLoop = 4; clsMotion[i].Rotatation[1] = BitConverter.ToSingle(buffer, nPtr); nPtr += nLoop; nLoop = 4; clsMotion[i].Rotatation[2] = BitConverter.ToSingle(buffer, nPtr); nPtr += nLoop; nLoop = 4; clsMotion[i].Rotatation[3] = BitConverter.ToSingle(buffer, nPtr); nPtr += nLoop; nLoop = 64; for (j = 0; j < nLoop; j++) { clsMotion[i].Interpolation[j] = buffer[nPtr + j]; } nPtr += nLoop; } } // Skin nLoop = 4; uiSkinCount = BitConverter.ToUInt32(buffer, nPtr); nPtr += nLoop; if (uiSkinCount > 0) { clsSkin = new VMD_SKIN[uiSkinCount]; for (i = 0; i < (int)uiSkinCount; i++) { clsSkin[i] = new VMD_SKIN(); nLoop = 15; for (j = 0; j < nLoop; j++) { clsSkin[i].SkinName[j] = buffer[nPtr + j]; if (buffer[nPtr + j] == '\0') { break; } } clsSkin[i].sSkinName = Encoding.GetEncoding("shift_jis").GetString(clsSkin[i].SkinName, 0, j); nPtr += nLoop; nLoop = 4; clsSkin[i].FrameNo = BitConverter.ToUInt32(buffer, nPtr); nPtr += nLoop; nLoop = 4; clsSkin[i].Weight = BitConverter.ToSingle(buffer, nPtr); nPtr += nLoop; } } // Camera nLoop = 4; uiCameraCount = BitConverter.ToUInt32(buffer, nPtr); nPtr += nLoop; if (uiCameraCount > 0) { clsCamera = new VMD_CAMERA[uiCameraCount]; for (i = 0; i < (int)uiCameraCount; i++) { clsCamera[i] = new VMD_CAMERA(); nLoop = 4; clsCamera[i].FrameNo = BitConverter.ToUInt32(buffer, nPtr); nPtr += nLoop; nLoop = 4; clsCamera[i].Length = BitConverter.ToSingle(buffer, nPtr); nPtr += nLoop; nLoop = 4; clsCamera[i].Location[0] = BitConverter.ToSingle(buffer, nPtr); nPtr += nLoop; nLoop = 4; clsCamera[i].Location[1] = BitConverter.ToSingle(buffer, nPtr); nPtr += nLoop; nLoop = 4; clsCamera[i].Location[2] = BitConverter.ToSingle(buffer, nPtr); nPtr += nLoop; nLoop = 4; clsCamera[i].Rotation[0] = BitConverter.ToSingle(buffer, nPtr); nPtr += nLoop; nLoop = 4; clsCamera[i].Rotation[1] = BitConverter.ToSingle(buffer, nPtr); nPtr += nLoop; nLoop = 4; clsCamera[i].Rotation[2] = BitConverter.ToSingle(buffer, nPtr); nPtr += nLoop; nLoop = 24; for (j = 0; j < nLoop; j++) { clsCamera[i].Interpolation[j] = buffer[nPtr + j]; } nPtr += nLoop; nLoop = 4; clsCamera[i].ViewingAngle = BitConverter.ToUInt32(buffer, nPtr); nPtr += nLoop; nLoop = 1; clsCamera[i].Perspective = buffer[nPtr]; nPtr += nLoop; } } // Light nLoop = 4; uiLightCount = BitConverter.ToUInt32(buffer, nPtr); nPtr += nLoop; if (uiLightCount > 0) { clsLight = new VMD_LIGHT[uiLightCount]; for (i = 0; i < (int)uiLightCount; i++) { clsLight[i] = new VMD_LIGHT(); nLoop = 4; clsLight[i].FrameNo = BitConverter.ToUInt32(buffer, nPtr); nPtr += nLoop; nLoop = 4; clsLight[i].RGB[0] = BitConverter.ToSingle(buffer, nPtr); nPtr += nLoop; nLoop = 4; clsLight[i].RGB[1] = BitConverter.ToSingle(buffer, nPtr); nPtr += nLoop; nLoop = 4; clsLight[i].RGB[2] = BitConverter.ToSingle(buffer, nPtr); nPtr += nLoop; nLoop = 4; clsLight[i].Location[0] = BitConverter.ToSingle(buffer, nPtr); nPtr += nLoop; nLoop = 4; clsLight[i].Location[1] = BitConverter.ToSingle(buffer, nPtr); nPtr += nLoop; nLoop = 4; clsLight[i].Location[2] = BitConverter.ToSingle(buffer, nPtr); nPtr += nLoop; } } // ここからはあるかどうかわからんからな... // SelfShadow uiSelfShadowCount = 0; if (nPtr < buffer.Length) { nLoop = 4; uiSelfShadowCount = BitConverter.ToUInt32(buffer, nPtr); nPtr += nLoop; if (uiSelfShadowCount > 0) { clsSelfShadow = new VMD_SELF_SHADOW[uiSelfShadowCount]; for (i = 0; i < (int)uiSelfShadowCount; i++) { clsSelfShadow[i] = new VMD_SELF_SHADOW(); nLoop = 4; clsSelfShadow[i].FrameNo = BitConverter.ToUInt32(buffer, nPtr); nPtr += nLoop; nLoop = 1; clsSelfShadow[i].Mode = buffer[nPtr]; nPtr += nLoop; nLoop = 4; clsSelfShadow[i].Distance = BitConverter.ToSingle(buffer, nPtr); nPtr += nLoop; } } } // IK uiShowIKCount = 0; if (nPtr < buffer.Length) { nLoop = 4; uiShowIKCount = BitConverter.ToUInt32(buffer, nPtr); nPtr += nLoop; if (uiShowIKCount > 0) { clsShowIK = new VMD_SHOWIKFRAME[uiShowIKCount]; for (i = 0; i < (int)uiShowIKCount; i++) { clsShowIK[i] = new VMD_SHOWIKFRAME(); nLoop = 4; clsShowIK[i].FrameNo = BitConverter.ToUInt32(buffer, nPtr); nPtr += nLoop; nLoop = 1; clsShowIK[i].show = buffer[nPtr]; nPtr += nLoop; nLoop = 4; clsShowIK[i].ik_count = BitConverter.ToUInt32(buffer, nPtr); nPtr += nLoop; if (clsShowIK[i].ik_count > 0) { clsShowIK[i].ik = new VMD_InfoIK[clsShowIK[i].ik_count]; for (int k = 0; k < clsShowIK[i].ik_count; k++) { clsShowIK[i].ik[k] = new VMD_InfoIK(); nLoop = 20; for (j = 0; j < nLoop; j++) { clsShowIK[i].ik[k].name[j] = buffer[nPtr + j]; if (buffer[nPtr + j] == '\0') { break; } } nPtr += nLoop; string ss = Encoding.GetEncoding("shift_jis").GetString(clsShowIK[i].ik[k].name); nLoop = 1; clsShowIK[i].ik[k].on_off = buffer[nPtr]; nPtr += nLoop; } } } } } return(true); }