import pmx plugin
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace LibMMD.Util
|
||||
{
|
||||
using System.Threading;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class BlockingQueue<T>
|
||||
{
|
||||
private int _count;
|
||||
|
||||
private readonly Queue<T> _queue = new Queue<T>();
|
||||
|
||||
private readonly int _maxSize;
|
||||
|
||||
public BlockingQueue(int maxSize = int.MaxValue)
|
||||
{
|
||||
_maxSize = maxSize;
|
||||
}
|
||||
|
||||
public int MaxSize
|
||||
{
|
||||
get { return _maxSize; }
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_queue)
|
||||
{
|
||||
return _count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public T DequeueNonBlocking()
|
||||
{
|
||||
lock (_queue)
|
||||
{
|
||||
if (_count <= 0)
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
|
||||
_count--;
|
||||
|
||||
var ret = _queue.Dequeue();
|
||||
Monitor.PulseAll(_queue);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
public T Dequeue()
|
||||
{
|
||||
lock (_queue)
|
||||
{
|
||||
// If we have items remaining in the queue, skip over this.
|
||||
while (_count <= 0)
|
||||
{
|
||||
Monitor.Wait(_queue);
|
||||
}
|
||||
|
||||
_count--;
|
||||
|
||||
var ret = _queue.Dequeue();
|
||||
Monitor.PulseAll(_queue);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
public int Enqueue(T data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
throw new ArgumentNullException("data is null");
|
||||
}
|
||||
|
||||
lock (_queue)
|
||||
{
|
||||
while (_count >= _maxSize)
|
||||
{
|
||||
Monitor.Wait(_queue);
|
||||
}
|
||||
|
||||
_queue.Enqueue(data);
|
||||
|
||||
_count++;
|
||||
|
||||
Monitor.PulseAll(_queue);
|
||||
return _count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee362629fc8ffc94b9188285001e0ce2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
|
||||
namespace LibMMD.Util
|
||||
{
|
||||
public static class LogUtil
|
||||
{
|
||||
public static void Debug(string format, params object[] args)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static void Info(string format, params object[] args)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static void Warn(string format, params object[] args)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static void Error(string format, params object[] args)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: babd7022c37a7544989f502bd0f3e8d7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using LibMMD.Reader;
|
||||
using UnityEngine;
|
||||
|
||||
namespace LibMMD.Util
|
||||
{
|
||||
public static class MMDReaderUtil
|
||||
{
|
||||
const float WorldSizeAmplifier = 0.08f;
|
||||
|
||||
public static string ReadStringFixedLength(BinaryReader reader, int length, Encoding encoding)
|
||||
{
|
||||
if (length < 0)
|
||||
{
|
||||
throw new MMDFileParseException("pmx string length is negative");
|
||||
}
|
||||
if (length == 0)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
var bytes = reader.ReadBytes(length);
|
||||
var str = encoding.GetString(bytes);
|
||||
var end = str.IndexOf("\0", StringComparison.Ordinal);
|
||||
if (end >= 0)
|
||||
{
|
||||
str = str.Substring(0, end);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public static string ReadSizedString(BinaryReader reader, Encoding encoding)
|
||||
{
|
||||
var length = reader.ReadInt32();
|
||||
return ReadStringFixedLength(reader, length, encoding);
|
||||
}
|
||||
|
||||
public static Vector4 ReadVector4(BinaryReader reader)
|
||||
{
|
||||
var ret = new Vector4();
|
||||
ret[0] = MathUtil.NanToZero(reader.ReadSingle());
|
||||
ret[1] = MathUtil.NanToZero(reader.ReadSingle());
|
||||
ret[2] = MathUtil.NanToZero(reader.ReadSingle());
|
||||
ret[3] = MathUtil.NanToZero(reader.ReadSingle());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Quaternion ReadQuaternion(BinaryReader reader)
|
||||
{
|
||||
var ret = new Quaternion();
|
||||
ret.x = -MathUtil.NanToZero(reader.ReadSingle());
|
||||
ret.y = MathUtil.NanToZero(reader.ReadSingle());
|
||||
ret.z = -MathUtil.NanToZero(reader.ReadSingle());
|
||||
ret.w = MathUtil.NanToZero(reader.ReadSingle());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Vector3 ReadVector3(BinaryReader reader)
|
||||
{
|
||||
return ReadAmpVector3(reader, WorldSizeAmplifier);
|
||||
}
|
||||
|
||||
public static Vector3 ReadAmpVector3(BinaryReader reader, float amp)
|
||||
{
|
||||
var ret = new Vector3();
|
||||
ret[0] = -MathUtil.NanToZero(reader.ReadSingle()) * amp;
|
||||
ret[1] = MathUtil.NanToZero(reader.ReadSingle()) * amp;
|
||||
ret[2] = -MathUtil.NanToZero(reader.ReadSingle()) * amp;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Vector3 ReadRawCoordinateVector3(BinaryReader reader)
|
||||
{
|
||||
var ret = new Vector3();
|
||||
ret[0] = MathUtil.NanToZero(reader.ReadSingle()) * WorldSizeAmplifier;
|
||||
ret[1] = MathUtil.NanToZero(reader.ReadSingle()) * WorldSizeAmplifier;
|
||||
ret[2] = MathUtil.NanToZero(reader.ReadSingle()) * WorldSizeAmplifier;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public static Vector2 ReadVector2(BinaryReader reader)
|
||||
{
|
||||
var ret = new Vector2();
|
||||
ret[0] = MathUtil.NanToZero(reader.ReadSingle());
|
||||
ret[1] = MathUtil.NanToZero(reader.ReadSingle());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static int ReadIndex(BinaryReader reader, int size)
|
||||
{
|
||||
switch (size)
|
||||
{
|
||||
case 1:
|
||||
return reader.ReadSByte();
|
||||
case 2:
|
||||
return reader.ReadUInt16();
|
||||
case 4:
|
||||
return reader.ReadInt32();
|
||||
default:
|
||||
throw new MMDFileParseException("invalid index size: " + size);
|
||||
}
|
||||
}
|
||||
|
||||
public static Color ReadColor(BinaryReader reader, bool readA)
|
||||
{
|
||||
var ret = new Color
|
||||
{
|
||||
r = reader.ReadSingle(),
|
||||
g = reader.ReadSingle(),
|
||||
b = reader.ReadSingle(),
|
||||
a = readA ? reader.ReadSingle() : 1.0f
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static bool Eof(BinaryReader binaryReader)
|
||||
{
|
||||
var bs = binaryReader.BaseStream;
|
||||
return (bs.Position == bs.Length);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 09e79f8045c6b81438f0b24590059aea
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,31 @@
|
||||
using LibMMD.Material;
|
||||
|
||||
namespace LibMMD.Util
|
||||
{
|
||||
public static class MMDTextureUtil
|
||||
{
|
||||
private static readonly string[] GlobalToonNames =
|
||||
{
|
||||
"toon0.bmp",
|
||||
"toon01.bmp",
|
||||
"toon02.bmp",
|
||||
"toon03.bmp",
|
||||
"toon04.bmp",
|
||||
"toon05.bmp",
|
||||
"toon06.bmp",
|
||||
"toon07.bmp",
|
||||
"toon08.bmp",
|
||||
"toon09.bmp",
|
||||
"toon10.bmp"
|
||||
};
|
||||
|
||||
public static MMDTexture GetGlobalToon(int index, string rootPath)
|
||||
{
|
||||
if (index >= 0 && index < GlobalToonNames.Length - 1)
|
||||
{
|
||||
return new MMDTexture(GlobalToonNames[index + 1]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62a8a9476e1c6cb4591487bbb1cbcb7c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,277 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Quaternion = UnityEngine.Quaternion;
|
||||
using Vector3 = UnityEngine.Vector3;
|
||||
|
||||
namespace LibMMD.Util
|
||||
{
|
||||
public static class MathUtil
|
||||
{
|
||||
public static Matrix4x4 Matrix4X4MuliplyFloat(Matrix4x4 mat, float val)
|
||||
{
|
||||
return new Matrix4x4
|
||||
{
|
||||
m00 = mat.m00 * val,
|
||||
m01 = mat.m01 * val,
|
||||
m02 = mat.m02 * val,
|
||||
m03 = mat.m03 * val,
|
||||
m10 = mat.m10 * val,
|
||||
m11 = mat.m11 * val,
|
||||
m12 = mat.m12 * val,
|
||||
m13 = mat.m13 * val,
|
||||
m20 = mat.m20 * val,
|
||||
m21 = mat.m21 * val,
|
||||
m22 = mat.m22 * val,
|
||||
m23 = mat.m23 * val,
|
||||
m30 = mat.m30 * val,
|
||||
m31 = mat.m31 * val,
|
||||
m32 = mat.m32 * val,
|
||||
m33 = mat.m33 * val
|
||||
};
|
||||
}
|
||||
|
||||
public static Matrix4x4 Matrix4X4Add(Matrix4x4 mat1, Matrix4x4 mat2)
|
||||
{
|
||||
return new Matrix4x4
|
||||
{
|
||||
m00 = mat1.m00 + mat2.m00,
|
||||
m01 = mat1.m01 + mat2.m01,
|
||||
m02 = mat1.m02 + mat2.m02,
|
||||
m03 = mat1.m03 + mat2.m03,
|
||||
m10 = mat1.m10 + mat2.m10,
|
||||
m11 = mat1.m11 + mat2.m11,
|
||||
m12 = mat1.m12 + mat2.m12,
|
||||
m13 = mat1.m13 + mat2.m13,
|
||||
m20 = mat1.m20 + mat2.m20,
|
||||
m21 = mat1.m21 + mat2.m21,
|
||||
m22 = mat1.m22 + mat2.m22,
|
||||
m23 = mat1.m23 + mat2.m23,
|
||||
m30 = mat1.m30 + mat2.m30,
|
||||
m31 = mat1.m31 + mat2.m31,
|
||||
m32 = mat1.m32 + mat2.m32,
|
||||
m33 = mat1.m33 + mat2.m33
|
||||
};
|
||||
}
|
||||
|
||||
public static Matrix4x4 QuaternionToMatrix4X4(Quaternion quaternion)
|
||||
{
|
||||
return Matrix4x4.TRS(Vector3.zero, quaternion, Vector3.one);
|
||||
}
|
||||
|
||||
public static Vector3 GetTransFromMatrix4X4(Matrix4x4 mat)
|
||||
{
|
||||
return new Vector3(mat.m03, mat.m13, mat.m23);
|
||||
}
|
||||
|
||||
public static void SetTransToMatrix4X4(Vector3 trans, ref Matrix4x4 mat)
|
||||
{
|
||||
mat.m03 = trans[0];
|
||||
mat.m13 = trans[1];
|
||||
mat.m23 = trans[2];
|
||||
}
|
||||
|
||||
public static Vector3 Matrix4x4ColDowngrade(Matrix4x4 mat, int col)
|
||||
{
|
||||
return new Vector3(mat[0, col], mat[1, col], mat[2, col]);
|
||||
}
|
||||
|
||||
public static Vector3 QuaternionToXyz(Quaternion quaternion)
|
||||
{
|
||||
var ii = quaternion.x * quaternion.x;
|
||||
var jj = quaternion.y * quaternion.y;
|
||||
var kk = quaternion.z * quaternion.z;
|
||||
var ei = quaternion.w * quaternion.x;
|
||||
var ej = quaternion.w * quaternion.y;
|
||||
var ek = quaternion.w * quaternion.z;
|
||||
var ij = quaternion.x * quaternion.y;
|
||||
var ik = quaternion.x * quaternion.z;
|
||||
var jk = quaternion.y * quaternion.z;
|
||||
Vector3 result;
|
||||
result.x = (float) Math.Atan2(2.0f * (ei - jk), 1 - 2.0f * (ii + jj));
|
||||
result.y = (float) Math.Asin(2.0f * (ej + ik));
|
||||
result.z = (float) Math.Atan2(2.0f * (ek - ij), 1 - 2.0f * (jj + kk));
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Vector3 QuaternionToXzy(Quaternion quaternion)
|
||||
{
|
||||
var ii = quaternion.x * quaternion.x;
|
||||
var jj = quaternion.y * quaternion.y;
|
||||
var kk = quaternion.z * quaternion.z;
|
||||
var ei = quaternion.w * quaternion.x;
|
||||
var ej = quaternion.w * quaternion.y;
|
||||
var ek = quaternion.w * quaternion.z;
|
||||
var ij = quaternion.x * quaternion.y;
|
||||
var ik = quaternion.x * quaternion.z;
|
||||
var jk = quaternion.y * quaternion.z;
|
||||
Vector3 result;
|
||||
result.x = (float) Math.Atan2(2.0f * (ei + jk), 1 - 2.0f * (ii + kk));
|
||||
result.y = (float) Math.Atan2(2.0f * (ej + ik), 1 - 2.0f * (jj + kk));
|
||||
result.z = (float) Math.Asin(2.0f * (ek - ij));
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Vector3 QuaternionToYxz(Quaternion quaternion)
|
||||
{
|
||||
var ii = quaternion.x * quaternion.x;
|
||||
var jj = quaternion.y * quaternion.y;
|
||||
var kk = quaternion.z * quaternion.z;
|
||||
var ei = quaternion.w * quaternion.x;
|
||||
var ej = quaternion.w * quaternion.y;
|
||||
var ek = quaternion.w * quaternion.z;
|
||||
var ij = quaternion.x * quaternion.y;
|
||||
var ik = quaternion.x * quaternion.z;
|
||||
var jk = quaternion.y * quaternion.z;
|
||||
Vector3 result;
|
||||
result.x = (float) Math.Asin(2.0f * (ei - jk));
|
||||
result.y = (float) Math.Atan2(2.0f * (ej + ik), 1 - 2.0f * (ii + jj));
|
||||
result.z = (float) Math.Atan2(2.0f * (ek + ij), 1 - 2.0f * (ii + kk));
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Vector3 QuaternionToYzx(Quaternion quaternion)
|
||||
{
|
||||
var ii = quaternion.x * quaternion.x;
|
||||
var jj = quaternion.y * quaternion.y;
|
||||
var kk = quaternion.z * quaternion.z;
|
||||
var ei = quaternion.w * quaternion.x;
|
||||
var ej = quaternion.w * quaternion.y;
|
||||
var ek = quaternion.w * quaternion.z;
|
||||
var ij = quaternion.x * quaternion.y;
|
||||
var ik = quaternion.x * quaternion.z;
|
||||
var jk = quaternion.y * quaternion.z;
|
||||
Vector3 result;
|
||||
result.x = (float) Math.Atan2(2.0f * (ei - jk), 1 - 2.0f * (ii + kk));
|
||||
result.y = (float) Math.Atan2(2.0f * (ej - ik), 1 - 2.0f * (jj + kk));
|
||||
result.z = (float) Math.Asin(2.0f * (ek + ij));
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Vector3 QuaternionToZxy(Quaternion quaternion)
|
||||
{
|
||||
var ii = quaternion.x * quaternion.x;
|
||||
var jj = quaternion.y * quaternion.y;
|
||||
var kk = quaternion.z * quaternion.z;
|
||||
var ei = quaternion.w * quaternion.x;
|
||||
var ej = quaternion.w * quaternion.y;
|
||||
var ek = quaternion.w * quaternion.z;
|
||||
var ij = quaternion.x * quaternion.y;
|
||||
var ik = quaternion.x * quaternion.z;
|
||||
var jk = quaternion.y * quaternion.z;
|
||||
Vector3 result;
|
||||
result.x = (float) Math.Asin(2.0f * (ei + jk));
|
||||
result.y = (float) Math.Atan2(2.0f * (ej - ik), 1 - 2.0f * (ii + jj));
|
||||
result.z = (float) Math.Atan2(2.0f * (ek - ij), 1 - 2.0f * (ii + kk));
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Vector3 QuaternionToZyx(Quaternion quaternion)
|
||||
{
|
||||
var ii = quaternion.x * quaternion.x;
|
||||
var jj = quaternion.y * quaternion.y;
|
||||
var kk = quaternion.z * quaternion.z;
|
||||
var ei = quaternion.w * quaternion.x;
|
||||
var ej = quaternion.w * quaternion.y;
|
||||
var ek = quaternion.w * quaternion.z;
|
||||
var ij = quaternion.x * quaternion.y;
|
||||
var ik = quaternion.x * quaternion.z;
|
||||
var jk = quaternion.y * quaternion.z;
|
||||
Vector3 result;
|
||||
result.x = (float) Math.Atan2(2.0f * (ei + jk), 1 - 2.0f * (ii + jj));
|
||||
result.y = (float) Math.Asin(2.0f * (ej - ik));
|
||||
result.z = (float) Math.Atan2(2.0f * (ek + ij), 1 - 2.0f * (jj + kk));
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Quaternion XyzToQuaternion(Vector3 euler) {
|
||||
var cx = Math.Cos(euler.x*0.5f);
|
||||
var sx = Math.Sin(euler.x*0.5f);
|
||||
var cy = Math.Cos(euler.y*0.5f);
|
||||
var sy = Math.Sin(euler.y*0.5f);
|
||||
var cz = Math.Cos(euler.z*0.5f);
|
||||
var sz = Math.Sin(euler.z*0.5f);
|
||||
Quaternion result;
|
||||
result.w = (float) (cx*cy*cz-sx*sy*sz);
|
||||
result.x = (float) (sx*cy*cz+cx*sy*sz);
|
||||
result.y = (float) (cx*sy*cz-sx*cy*sz);
|
||||
result.z = (float) (sx*sy*cz+cx*cy*sz);
|
||||
return result;
|
||||
}
|
||||
public static Quaternion XzyToQuaternion(Vector3 euler) {
|
||||
var cx = Math.Cos(euler.x*0.5f);
|
||||
var sx = Math.Sin(euler.x*0.5f);
|
||||
var cy = Math.Cos(euler.y*0.5f);
|
||||
var sy = Math.Sin(euler.y*0.5f);
|
||||
var cz = Math.Cos(euler.z*0.5f);
|
||||
var sz = Math.Sin(euler.z*0.5f);
|
||||
Quaternion result;
|
||||
result.w = (float) (cx*cy*cz+sx*sy*sz);
|
||||
result.x = (float) (sx*cy*cz-cx*sy*sz);
|
||||
result.y = (float) (cx*sy*cz-sx*cy*sz);
|
||||
result.z = (float) (cx*cy*sz+sx*sy*cz);
|
||||
return result;
|
||||
}
|
||||
public static Quaternion YxzToQuaternion(Vector3 euler) {
|
||||
var cx = Math.Cos(euler.x*0.5f);
|
||||
var sx = Math.Sin(euler.x*0.5f);
|
||||
var cy = Math.Cos(euler.y*0.5f);
|
||||
var sy = Math.Sin(euler.y*0.5f);
|
||||
var cz = Math.Cos(euler.z*0.5f);
|
||||
var sz = Math.Sin(euler.z*0.5f);
|
||||
Quaternion result;
|
||||
result.w = (float) (cx*cy*cz+sx*sy*sz);
|
||||
result.x = (float) (sx*cy*cz+cx*sy*sz);
|
||||
result.y = (float) (cx*sy*cz-sx*cy*sz);
|
||||
result.z = (float) (cx*cy*sz-sx*sy*cz);
|
||||
return result;
|
||||
}
|
||||
public static Quaternion YzxToQuaternion(Vector3 euler) {
|
||||
var cx = Math.Cos(euler.x*0.5f);
|
||||
var sx = Math.Sin(euler.x*0.5f);
|
||||
var cy = Math.Cos(euler.y*0.5f);
|
||||
var sy = Math.Sin(euler.y*0.5f);
|
||||
var cz = Math.Cos(euler.z*0.5f);
|
||||
var sz = Math.Sin(euler.z*0.5f);
|
||||
Quaternion result;
|
||||
result.w = (float) (cx*cy*cz-sx*sy*sz);
|
||||
result.x = (float) (sx*cy*cz+cx*sy*sz);
|
||||
result.y = (float) (cx*sy*cz+sx*cy*sz);
|
||||
result.z = (float) (cx*cy*sz-sx*sy*cz);
|
||||
return result;
|
||||
}
|
||||
public static Quaternion ZxyToQuaternion(Vector3 euler) {
|
||||
var cx = Math.Cos(euler.x*0.5f);
|
||||
var sx = Math.Sin(euler.x*0.5f);
|
||||
var cy = Math.Cos(euler.y*0.5f);
|
||||
var sy = Math.Sin(euler.y*0.5f);
|
||||
var cz = Math.Cos(euler.z*0.5f);
|
||||
var sz = Math.Sin(euler.z*0.5f);
|
||||
Quaternion result;
|
||||
result.w = (float) (cx*cy*cz-sx*sy*sz);
|
||||
result.x = (float) (sx*cy*cz-cx*sy*sz);
|
||||
result.y = (float) (cx*sy*cz+sx*cy*sz);
|
||||
result.z = (float) (cx*cy*sz+sx*sy*cz);
|
||||
return result;
|
||||
}
|
||||
public static Quaternion ZYXToQuaternion(Vector3 euler) {
|
||||
var cx = Math.Cos(euler.x*0.5f);
|
||||
var sx = Math.Sin(euler.x*0.5f);
|
||||
var cy = Math.Cos(euler.y*0.5f);
|
||||
var sy = Math.Sin(euler.y*0.5f);
|
||||
var cz = Math.Cos(euler.z*0.5f);
|
||||
var sz = Math.Sin(euler.z*0.5f);
|
||||
Quaternion result;
|
||||
result.w = (float) (cx*cy*cz+sx*sy*sz);
|
||||
result.x = (float) (sx*cy*cz-cx*sy*sz);
|
||||
result.y = (float) (cx*sy*cz+sx*cy*sz);
|
||||
result.z = (float) (cx*cy*sz-sx*sy*cz);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static float NanToZero(float f)
|
||||
{
|
||||
return float.IsNaN(f) ? 0.0f : f;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6530efcfb90ab7a4a979a57a9b4bfe7e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,40 @@
|
||||
namespace LibMMD.Util
|
||||
{
|
||||
using UnityEngine;
|
||||
|
||||
public static class MatrixExtensions
|
||||
{
|
||||
public static Quaternion ExtractRotation(this Matrix4x4 matrix)
|
||||
{
|
||||
Vector3 forward;
|
||||
forward.x = matrix.m02;
|
||||
forward.y = matrix.m12;
|
||||
forward.z = matrix.m22;
|
||||
|
||||
Vector3 upwards;
|
||||
upwards.x = matrix.m01;
|
||||
upwards.y = matrix.m11;
|
||||
upwards.z = matrix.m21;
|
||||
|
||||
return Quaternion.LookRotation(forward, upwards);
|
||||
}
|
||||
|
||||
public static Vector3 ExtractPosition(this Matrix4x4 matrix)
|
||||
{
|
||||
Vector3 position;
|
||||
position.x = matrix.m03;
|
||||
position.y = matrix.m13;
|
||||
position.z = matrix.m23;
|
||||
return position;
|
||||
}
|
||||
|
||||
public static Vector3 ExtractScale(this Matrix4x4 matrix)
|
||||
{
|
||||
Vector3 scale;
|
||||
scale.x = new Vector4(matrix.m00, matrix.m10, matrix.m20, matrix.m30).magnitude;
|
||||
scale.y = new Vector4(matrix.m01, matrix.m11, matrix.m21, matrix.m31).magnitude;
|
||||
scale.z = new Vector4(matrix.m02, matrix.m12, matrix.m22, matrix.m32).magnitude;
|
||||
return scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d6aa1afffc18d7442a0868b263a9649c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,33 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace LibMMD.Util
|
||||
{
|
||||
public class SynchronizedQueue<T>
|
||||
{
|
||||
private readonly Queue<T> _queue = new Queue<T>();
|
||||
|
||||
public void Enqueue(T val)
|
||||
{
|
||||
lock (_queue)
|
||||
{
|
||||
_queue.Enqueue(val);
|
||||
}
|
||||
}
|
||||
|
||||
public T Take()
|
||||
{
|
||||
lock (_queue)
|
||||
{
|
||||
return _queue.Count <= 0 ? default(T) : _queue.Dequeue();
|
||||
}
|
||||
}
|
||||
|
||||
public int Count()
|
||||
{
|
||||
lock (_queue)
|
||||
{
|
||||
return _queue.Count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 173dfc038c2acc847922d19569b1fc38
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.Text;
|
||||
|
||||
namespace LibMMD.Util
|
||||
{
|
||||
public static class Tools
|
||||
{
|
||||
public static readonly Encoding JapaneseEncoding = Encoding.GetEncoding(932);
|
||||
public const float MmdMathConstEps = (float) 1.0e-7;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c38c1832b9c7a004f8cc6624b772ee32
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,14 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace LibMMD.Util
|
||||
{
|
||||
public static class TransformExtensions
|
||||
{
|
||||
public static void FromMatrix(this Transform transform, Matrix4x4 matrix)
|
||||
{
|
||||
transform.localScale = matrix.ExtractScale();
|
||||
transform.rotation = matrix.ExtractRotation();
|
||||
transform.position = matrix.ExtractPosition();
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f9aee4e9b09a134c8bc6e55f76f6df1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user