import pmx plugin
This commit is contained in:
@@ -0,0 +1,160 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace LibMMD.Model
|
||||
{
|
||||
public class Bone
|
||||
{
|
||||
public class IkLink
|
||||
{
|
||||
public int LinkIndex { get; set; }
|
||||
public bool HasLimit { get; set; }
|
||||
public Vector3 LoLimit { get; set; }
|
||||
public Vector3 HiLimit { get; set; }
|
||||
|
||||
public static IkLink CopyOf(IkLink ikLink)
|
||||
{
|
||||
return new IkLink
|
||||
{
|
||||
LinkIndex = ikLink.LinkIndex,
|
||||
HasLimit = ikLink.HasLimit,
|
||||
LoLimit = ikLink.LoLimit,
|
||||
HiLimit = ikLink.HiLimit
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class ChildBone
|
||||
{
|
||||
public bool ChildUseId { get; set; }
|
||||
public Vector3 Offset { get; set; }
|
||||
public int Index { get; set; }
|
||||
|
||||
public static ChildBone CopyOf(ChildBone childBone)
|
||||
{
|
||||
return new ChildBone
|
||||
{
|
||||
ChildUseId = childBone.ChildUseId,
|
||||
Offset = childBone.Offset,
|
||||
Index = childBone.Index
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class AppendBone
|
||||
{
|
||||
public int Index { get; set; }
|
||||
public float Ratio { get; set; }
|
||||
|
||||
public static AppendBone CopyOf(AppendBone appendBone)
|
||||
{
|
||||
return new AppendBone
|
||||
{
|
||||
Index = appendBone.Index,
|
||||
Ratio = appendBone.Ratio
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class IkInfo
|
||||
{
|
||||
public int IkTargetIndex { get; set; }
|
||||
public int CcdIterateLimit { get; set; }
|
||||
public float CcdAngleLimit { get; set; }
|
||||
public IkLink[] IkLinks { get; set; }
|
||||
|
||||
public static IkInfo CopyOf(IkInfo ikInfo)
|
||||
{
|
||||
var ikLinksCopy = new IkLink[ikInfo.IkLinks.Length];
|
||||
ikInfo.IkLinks.CopyTo(ikLinksCopy, 0);
|
||||
return new IkInfo
|
||||
{
|
||||
IkTargetIndex = ikInfo.IkTargetIndex,
|
||||
CcdIterateLimit = ikInfo.CcdIterateLimit,
|
||||
CcdAngleLimit = ikInfo.CcdAngleLimit,
|
||||
IkLinks = ikLinksCopy
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class LocalAxis
|
||||
{
|
||||
public Vector3 AxisX { get; set; }
|
||||
public Vector3 AxisY { get; set; }
|
||||
public Vector3 AxisZ { get; set; }
|
||||
|
||||
public static LocalAxis CopyOf(LocalAxis localAxis)
|
||||
{
|
||||
return new LocalAxis
|
||||
{
|
||||
AxisX = localAxis.AxisX,
|
||||
AxisY = localAxis.AxisY,
|
||||
AxisZ = localAxis.AxisZ
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public Bone()
|
||||
{
|
||||
ChildBoneVal = new ChildBone();
|
||||
AppendBoneVal = new AppendBone();
|
||||
LocalAxisVal = new LocalAxis();
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
public string NameEn { get; set; }
|
||||
public Vector3 Position { get; set; }
|
||||
public int ParentIndex { get; set; }
|
||||
public int TransformLevel { get; set; }
|
||||
public bool Rotatable { get; set; }
|
||||
public bool Movable { get; set; }
|
||||
public bool Visible { get; set; }
|
||||
public bool Controllable { get; set; }
|
||||
public bool HasIk { get; set; }
|
||||
public bool AppendRotate { get; set; }
|
||||
public bool AppendTranslate { get; set; }
|
||||
public bool RotAxisFixed { get; set; }
|
||||
public bool UseLocalAxis { get; set; }
|
||||
public bool PostPhysics { get; set; }
|
||||
public bool ReceiveTransform { get; set; }
|
||||
public ChildBone ChildBoneVal { get; set; }
|
||||
public AppendBone AppendBoneVal { get; set; }
|
||||
public Vector3 RotAxis { get; set; }
|
||||
public LocalAxis LocalAxisVal { get; set; }
|
||||
public int ExportKey { get; set; }
|
||||
public IkInfo IkInfoVal { get; set; }
|
||||
|
||||
public static Bone CopyOf(Bone bone)
|
||||
{
|
||||
return new Bone
|
||||
{
|
||||
Name = bone.Name,
|
||||
NameEn = bone.NameEn,
|
||||
Position = bone.Position,
|
||||
ParentIndex = bone.ParentIndex,
|
||||
TransformLevel = bone.TransformLevel,
|
||||
Rotatable = bone.Rotatable,
|
||||
Movable = bone.Movable,
|
||||
Visible = bone.Visible,
|
||||
Controllable = bone.Controllable,
|
||||
HasIk = bone.HasIk,
|
||||
AppendRotate = bone.AppendRotate,
|
||||
AppendTranslate = bone.AppendTranslate,
|
||||
RotAxisFixed = bone.RotAxisFixed,
|
||||
UseLocalAxis = bone.UseLocalAxis,
|
||||
PostPhysics = bone.PostPhysics,
|
||||
ReceiveTransform = bone.ReceiveTransform,
|
||||
ChildBoneVal = ChildBone.CopyOf(bone.ChildBoneVal),
|
||||
AppendBoneVal = AppendBone.CopyOf(bone.AppendBoneVal),
|
||||
RotAxis = bone.RotAxis,
|
||||
LocalAxisVal = LocalAxis.CopyOf(bone.LocalAxisVal),
|
||||
ExportKey = bone.ExportKey,
|
||||
IkInfoVal = IkInfo.CopyOf(bone.IkInfoVal),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0cd3fbcfbcc9edc4a8ba7660a838d4dc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,24 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace LibMMD.Model
|
||||
{
|
||||
public class Joint
|
||||
{
|
||||
public Joint()
|
||||
{
|
||||
AssociatedRigidBodyIndex = new int[2];
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
public string NameEn { get; set; }
|
||||
public int[] AssociatedRigidBodyIndex { get; set; }
|
||||
public Vector3 Position { get; set; }
|
||||
public Vector3 Rotation { get; set; }
|
||||
public Vector3 PositionLowLimit { get; set; }
|
||||
public Vector3 PositionHiLimit { get; set; }
|
||||
public Vector3 RotationLowLimit { get; set; }
|
||||
public Vector3 RotationHiLimit { get; set; }
|
||||
public Vector3 SpringTranslate { get; set; }
|
||||
public Vector3 SpringRotate { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 10f6db9a9b776f341bfd7b5aabda88ae
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,38 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace LibMMD.Model
|
||||
{
|
||||
public class MMDRigidBody
|
||||
{
|
||||
public enum RigidBodyShape : byte
|
||||
{
|
||||
RigidShapeSphere = 0x00,
|
||||
RigidShapeBox = 0x01,
|
||||
RigidShapeCapsule = 0x02
|
||||
}
|
||||
|
||||
public enum RigidBodyType : byte
|
||||
{
|
||||
RigidTypeKinematic = 0x00,
|
||||
RigidTypePhysics = 0x01,
|
||||
RigidTypePhysicsStrict = 0x02,
|
||||
RigidTypePhysicsGhost = 0x03
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
public string NameEn { get; set; }
|
||||
public int AssociatedBoneIndex { get; set; }
|
||||
public int CollisionGroup { get; set; }
|
||||
public ushort CollisionMask { get; set; }
|
||||
public RigidBodyShape Shape { get; set; }
|
||||
public Vector3 Dimemsions { get; set; }
|
||||
public Vector3 Position { get; set; }
|
||||
public Vector3 Rotation { get; set; }
|
||||
public float Mass { get; set; }
|
||||
public float TranslateDamp { get; set; }
|
||||
public float RotateDamp { get; set; }
|
||||
public float Restitution { get; set; }
|
||||
public float Friction { get; set; }
|
||||
public RigidBodyType Type { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 395400370dc114b4bbe68e03a1c99a0c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,87 @@
|
||||
using System.Collections.Generic;
|
||||
using LibMMD.Util;
|
||||
using UnityEngine;
|
||||
|
||||
namespace LibMMD.Model
|
||||
{
|
||||
public class Morph
|
||||
{
|
||||
public enum MorphCategory : byte
|
||||
{
|
||||
MorphCatSystem = 0x00,
|
||||
MorphCatEyebrow = 0x01,
|
||||
MorphCatEye = 0x02,
|
||||
MorphCatMouth = 0x03,
|
||||
MorphCatOther = 0x04
|
||||
}
|
||||
|
||||
public enum MorphType : byte
|
||||
{
|
||||
MorphTypeGroup = 0x00,
|
||||
MorphTypeVertex = 0x01,
|
||||
MorphTypeBone = 0x02,
|
||||
MorphTypeUv = 0x03,
|
||||
MorphTypeExtUv1 = 0x04,
|
||||
MorphTypeExtUv2 = 0x05,
|
||||
MorphTypeExtUv3 = 0x06,
|
||||
MorphTypeExtUv4 = 0x07,
|
||||
MorphTypeMaterial = 0x08
|
||||
}
|
||||
|
||||
public abstract class MorphData
|
||||
{
|
||||
}
|
||||
|
||||
public class GroupMorphData : MorphData
|
||||
{
|
||||
public int MorphIndex { get; set; }
|
||||
public float MorphRate { get; set; }
|
||||
}
|
||||
|
||||
public class VertexMorphData : MorphData
|
||||
{
|
||||
public int VertexIndex { get; set; }
|
||||
public Vector3 Offset { get; set; }
|
||||
}
|
||||
|
||||
public class BoneMorphData : MorphData
|
||||
{
|
||||
public int BoneIndex { get; set; }
|
||||
public Vector3 Translation { get; set; }
|
||||
public Quaternion Rotation { get; set; }
|
||||
}
|
||||
|
||||
public class UvMorphData : MorphData
|
||||
{
|
||||
public int VertexIndex { get; set; }
|
||||
public Vector4 Offset { get; set; }
|
||||
}
|
||||
|
||||
public class MaterialMorphData : MorphData
|
||||
{
|
||||
public enum MaterialMorphMethod : byte {
|
||||
MorphMatMul = 0x00,
|
||||
MorphMatAdd = 0x01
|
||||
}
|
||||
|
||||
public int MaterialIndex { get; set; }
|
||||
public bool Global { get; set; }
|
||||
public MaterialMorphMethod Method { get; set; }
|
||||
public Color Diffuse { get; set; }
|
||||
public Color Specular { get; set; }
|
||||
public Color Ambient { get; set; }
|
||||
public float Shiness { get; set; }
|
||||
public Color EdgeColor { get; set; }
|
||||
public float EdgeSize { get; set; }
|
||||
public Vector4 Texture { get; set; }
|
||||
public Vector4 SubTexture { get; set; }
|
||||
public Vector4 ToonTexture { get; set; }
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
public string NameEn { get; set; }
|
||||
public MorphCategory Category { get; set; }
|
||||
public MorphType Type { get; set; }
|
||||
public MorphData[] MorphDatas { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f7f998f4d72211a4bbfa615fed8ceacb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace LibMMD.Model
|
||||
{
|
||||
public class Part
|
||||
{
|
||||
public Material.MMDMaterial Material { get; set; }
|
||||
public int BaseShift { get; set; } //注意这个和libmmd里的含义不同,这里是三角形顶点数
|
||||
public int TriangleIndexNum { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d0fb693cf5950c84499b613bb97a23eb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
|
||||
namespace LibMMD.Model
|
||||
{
|
||||
public class RawMMDModel
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string NameEn { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string DescriptionEn { get; set; }
|
||||
public Vertex[] Vertices { get; set; }
|
||||
public int ExtraUvNumber { get; set; }
|
||||
public int[] TriangleIndexes { get; set; }
|
||||
public Part[] Parts { get; set; }
|
||||
public Bone[] Bones { get; set; }
|
||||
public Morph[] Morphs { get; set; }
|
||||
public MMDRigidBody[] Rigidbodies { get; set; }
|
||||
public Joint[] Joints { get; set; }
|
||||
|
||||
public void Normalize()
|
||||
{
|
||||
foreach (var vertex in Vertices)
|
||||
{
|
||||
switch (vertex.SkinningOperator.Type)
|
||||
{
|
||||
case SkinningOperator.SkinningType.SkinningBdef2:
|
||||
{
|
||||
var oldBdef2 = (SkinningOperator.Bdef2) vertex.SkinningOperator.Param;
|
||||
var weight = oldBdef2.BoneWeight;
|
||||
if (Math.Abs(weight) < 0.000001f)
|
||||
{
|
||||
var bdef1 = new SkinningOperator.Bdef1 {BoneId = oldBdef2.BoneId[1]};
|
||||
vertex.SkinningOperator.Param = bdef1;
|
||||
vertex.SkinningOperator.Type = SkinningOperator.SkinningType.SkinningBdef1;
|
||||
}
|
||||
else if (Math.Abs(weight - 1.0f) < 0.00001f)
|
||||
{
|
||||
var bdef1 = new SkinningOperator.Bdef1 {BoneId = oldBdef2.BoneId[0]};
|
||||
vertex.SkinningOperator.Param = bdef1;
|
||||
vertex.SkinningOperator.Type = SkinningOperator.SkinningType.SkinningBdef1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SkinningOperator.SkinningType.SkinningSdef:
|
||||
{
|
||||
var oldSdef = (SkinningOperator.Sdef) vertex.SkinningOperator.Param;
|
||||
var bone0 = oldSdef.BoneId[0];
|
||||
var bone1 = oldSdef.BoneId[1];
|
||||
var weight = oldSdef.BoneWeight;
|
||||
if (
|
||||
Bones[bone0].ParentIndex != bone1 &&
|
||||
Bones[bone1].ParentIndex != bone0
|
||||
)
|
||||
{
|
||||
if (Math.Abs(weight) < 0.000001f)
|
||||
{
|
||||
var bdef1 = new SkinningOperator.Bdef1 {BoneId = bone1};
|
||||
vertex.SkinningOperator.Param = bdef1;
|
||||
vertex.SkinningOperator.Type = SkinningOperator.SkinningType.SkinningBdef1;
|
||||
}
|
||||
else if (Math.Abs(weight - 1.0f) < 0.00001f)
|
||||
{
|
||||
var bdef1 = new SkinningOperator.Bdef1 {BoneId = bone0};
|
||||
vertex.SkinningOperator.Param = bdef1;
|
||||
vertex.SkinningOperator.Type = SkinningOperator.SkinningType.SkinningBdef1;
|
||||
}
|
||||
else
|
||||
{
|
||||
var bdef2 = new SkinningOperator.Bdef2();
|
||||
bdef2.BoneId[0] = bone0;
|
||||
bdef2.BoneId[1] = bone1;
|
||||
bdef2.BoneWeight = weight;
|
||||
vertex.SkinningOperator.Param = bdef2;
|
||||
vertex.SkinningOperator.Type = SkinningOperator.SkinningType.SkinningBdef2;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 05367ea617bee1747a4786e33ec02123
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,64 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace LibMMD.Model
|
||||
{
|
||||
public class SkinningOperator
|
||||
{
|
||||
public enum SkinningType : byte
|
||||
{
|
||||
SkinningBdef1 = 0,
|
||||
SkinningBdef2 = 1,
|
||||
SkinningBdef4 = 2,
|
||||
SkinningSdef = 3
|
||||
}
|
||||
|
||||
public abstract class SkinningParam
|
||||
{
|
||||
}
|
||||
|
||||
public class Bdef1 : SkinningParam
|
||||
{
|
||||
public int BoneId { get; set; }
|
||||
}
|
||||
|
||||
public class Bdef2 : SkinningParam
|
||||
{
|
||||
public Bdef2()
|
||||
{
|
||||
BoneId = new int[2];
|
||||
}
|
||||
|
||||
public int[] BoneId { get; set; }
|
||||
public float BoneWeight { get; set; }
|
||||
}
|
||||
|
||||
public class Bdef4 : SkinningParam
|
||||
{
|
||||
public Bdef4()
|
||||
{
|
||||
BoneId = new int[4];
|
||||
BoneWeight = new float[4];
|
||||
}
|
||||
|
||||
public int[] BoneId { get; set; }
|
||||
public float[] BoneWeight { get; set; }
|
||||
}
|
||||
|
||||
public class Sdef : SkinningParam
|
||||
{
|
||||
public Sdef()
|
||||
{
|
||||
BoneId = new int[2];
|
||||
}
|
||||
|
||||
public int[] BoneId { get; set; }
|
||||
public float BoneWeight { get; set; }
|
||||
public Vector3 C { get; set; }
|
||||
public Vector3 R0 { get; set; }
|
||||
public Vector3 R1 { get; set; }
|
||||
}
|
||||
|
||||
public SkinningType Type { get; set; }
|
||||
public SkinningParam Param { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fcf11bb8f382aff4d8e67cd1d879439e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,14 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace LibMMD.Model
|
||||
{
|
||||
public class Vertex
|
||||
{
|
||||
public Vector3 Coordinate { get; set; }
|
||||
public Vector3 Normal { get; set; }
|
||||
public Vector2 UvCoordinate { get; set; }
|
||||
public Vector4[] ExtraUvCoordinate { get; set; }
|
||||
public SkinningOperator SkinningOperator { get; set; }
|
||||
public float EdgeScale { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a8dee8727f3427b4eab957bef13ea4b6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user