Created
May 11, 2012 01:18
-
-
Save mfakane/2656910 to your computer and use it in GitHub Desktop.
MMDVer3 以降の .vmd から MMDVer2 で読み込める .vmd にする実験。必要ライブラリはコード内コメントを参照
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// requires SlimDX (or any 3D mathmatics library) and Keystone.IO | |
// Keystone.IO: https://github.com/mfakane/Keystone/tree/master/Keystone.IO | |
using System.IO; | |
using Linearstar.Keystone.IO.MikuMikuDance; | |
using SlimDX; | |
namespace ConsoleApplication1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// TODO: change it to your vmd file path. | |
ConvertCamera(@"X:\testCamera.vmd", @"X:\testCamera2.vmd"); | |
ConvertMotion(@"X:\testMotion.vmd", @"X:\testMotion2.vmd"); | |
} | |
static void ConvertMotion(string inputFile, string outputFile) | |
{ | |
using (var fs = File.OpenRead(inputFile)) | |
{ | |
var doc = VmdDocument.Parse(fs); | |
doc.Version = VmdVersion.MMDVer2; | |
doc.ModelName = "miku"; | |
foreach (var i in doc.BoneFrames) | |
if (i.Name != "センター" && !i.Name.EndsWith("IK")) | |
i.Position = new[] { 0f, 0, 0 }; | |
using (var ws = File.OpenWrite(outputFile)) | |
doc.Write(ws); | |
} | |
} | |
static void ConvertCamera(string inputFile, string outputFile) | |
{ | |
using (var fs = File.OpenRead(inputFile)) | |
{ | |
var doc = VmdDocument.Parse(fs); | |
doc.Version = VmdVersion.MMDVer2; | |
foreach (var i in doc.CameraFrames) | |
{ | |
var rotation = i.Angle; | |
var q = Quaternion.RotationYawPitchRoll(rotation[1], rotation[0], rotation[2]); | |
var up = Vector3.Transform(-Vector3.UnitY, q); | |
var offset = up * 6; | |
i.Position[0] += offset.X; | |
i.Position[1] += offset.Y; | |
i.Position[2] += offset.Z; | |
i.Radius *= 1 + i.FovInDegree / 45f; | |
} | |
using (var ws = File.OpenWrite(outputFile)) | |
doc.Write(ws); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment