pmx

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2021 License: Unlicense Imports: 5 Imported by: 0

Documentation

Overview

Package pmx 用来把PMX格式的3D模型读进内存.

Index

Constants

This section is empty.

Variables

View Source
var BoneNamesTable = map[string]string{
	"センター":   "center",
	"上半身":    "upper body",
	"首":      "neck",
	"頭":      "head",
	"左目":     "eye_L",
	"右目":     "eye_R",
	"ネクタイ1":  "necktie1",
	"ネクタイ2":  "necktie2",
	"ネクタイ3":  "necktie3",
	"下半身":    "lower body",
	"腰飾り":    "waist accessory",
	"左髪1":    "hair1_L",
	"左髪2":    "hair2_L",
	"左髪3":    "hair3_L",
	"左髪4":    "hair4_L",
	"左髪5":    "hair5_L",
	"左髪6":    "hair6_L",
	"左肩":     "shoulder_L",
	"左腕":     "arm_L",
	"左腕捩":    "arm twist_L",
	"左ひじ":    "elbow_L",
	"左手捩":    "wrist twist_L",
	"左手首":    "wrist_L",
	"左袖":     "sleeve_L",
	"左親指1":   "thumb1_L",
	"左親指2":   "thumb2_L",
	"左人指1":   "fore1_L",
	"左人指2":   "fore2_L",
	"左人指3":   "fore3_L",
	"左中指1":   "middle1_L",
	"左中指2":   "middle2_L",
	"左中指3":   "middle3_L",
	"左薬指1":   "third1_L",
	"左薬指2":   "third2_L",
	"左薬指3":   "third3_L",
	"左小指1":   "little1_L",
	"左小指2":   "little2_L",
	"左小指3":   "little3_L",
	"左スカート前": "front skirt_L",
	"左スカート後": "back skirt_L",
	"左足":     "leg_L",
	"左ひざ":    "knee_L",
	"左足首":    "ankle_L",
	"右髪1":    "hair1_R",
	"右髪2":    "hair2_R",
	"右髪3":    "hair3_R",
	"右髪4":    "hair4_R",
	"右髪5":    "hair5_R",
	"右髪6":    "hair6_R",
	"右肩":     "shoulder_R",
	"右腕":     "arm_R",
	"右腕捩":    "arm twist_R",
	"右ひじ":    "elbow_R",
	"右手捩":    "wrist twist_R",
	"右手首":    "wrist_R",
	"右袖":     "sleeve_R",
	"右親指1":   "thumb1_R",
	"右親指2":   "thumb2_R",
	"右人指1":   "fore1_R",
	"右人指2":   "fore2_R",
	"右人指3":   "fore3_R",
	"右中指1":   "middle1_R",
	"右中指2":   "middle2_R",
	"右中指3":   "middle3_R",
	"右薬指1":   "third1_R",
	"右薬指2":   "third2_R",
	"右薬指3":   "third3_R",
	"右小指1":   "little1_R",
	"右小指2":   "little2_R",
	"右小指3":   "little3_R",
	"右スカート前": "front skirt_R",
	"右スカート後": "back skirt_R",
	"右足":     "leg_R",
	"右ひざ":    "knee_R",
	"右足首":    "ankle_R",
	"両目":     "eyes",
	"前髪1":    "front hair1",
	"前髪2":    "front hair2",
	"前髪3":    "front hair3",
	"左目光":    "eyelight_L",
	"右目光":    "eyelight_R",
	"ネクタイ4":  "necktie4",
	"左髪7":    "hair7_L",
	"右髪7":    "hair7_R",
	"左つま先":   "toe_L",
	"右つま先":   "toe_R",
	"ネクタイIK": "necktie IK",
	"左髪IK":   "hair IK_L",
	"右髪IK":   "hair IK_R",
	"左足IK":   "leg IK_L",
	"右足IK":   "leg IK_R",
	"左つま先IK": "toe IK_L",
	"右つま先IK": "toe IK_R",
}

标准骨骼名称的日文英文对应表

View Source
var MorphNamesTable = map[string]string{
	"真面目":    "serious",
	"困る":     "sadness",
	"にこり":    "cheerful",
	"怒り":     "anger",
	"上":      "go up",
	"下":      "go down",
	"まばたき":   "blink",
	"笑い":     "smile",
	"ウィンク":   "wink",
	"ウィンク2":  "wink2",
	"ウィンク右":  "wink_R",
	"ウィンク2右": "wink2_R",
	"はぅ":     "close><",
	"なごみ":    "calm",
	"びっくり":   "surprise",
	"じと目":    "doubt",
	"なぬ!":    "confuse",
	"瞳小":     "pupil",
	"あ":      "a",
	"い":      "i",
	"う":      "u",
	"お":      "o",
	"▲":      "triangle",
	"∧":      "regret",
	"ω":      "omega",
	"ω□":     "omegabox",
	"はんっ!":   "fool",
	"ぺろっ":    "tongue",
	"えー":     "e-",
	"にやり":    "grin",
}

标准Morph(表情)动画名称的日文英文对应表

Functions

This section is empty.

Types

type AnchorRigidBody

type AnchorRigidBody struct {
	RigidBody int32
	Vertex    int32
	NearMode  uint8 // 0:OFF 1:ON
}

type Bone

type Bone struct {
	Name   string
	NameEN string

	Position   [3]float32
	Parent     int32
	MorphLevel int32 // 应该是用来控制变形的顺序

	Flags BoneFlags

	TailBone   int32      // 适用于 BONE_FLAG_TAIL_BONE==1
	TailOffset [3]float32 // 适用于 BONE_FLAG_TAIL_BONE==0

	AssignParent int32   // 适用于付与
	AssignFrac   float32 // 适用于付与

	FixedAxis [3]float32 // 限制轴的指向. (限制轴和本地轴可以同时打开)

	LocalXAxis [3]float32 // 适用于 BONE_FLAG_LOCAL_AXIS==1
	LocalZAxis [3]float32 // 适用于 BONE_FLAG_LOCAL_AXIS==1

	ExternalParent int32 // 适用于 ExternalParent

	IKTargetBone      int32    // 适用于 IK
	IKLoop            int32    // 循环次数, 适用于 IK
	IKAngleDeltaLimit float32  // IK单步角度限制(弧度角), 适用于 IK
	IKLink            []IKLink // IK链表, 适用于 IK
}

骨骼

type BoneFlags

type BoneFlags uint16
const (
	BONE_FLAG_TAIL_BONE             BoneFlags = 1 << iota // 骨骼尾部连接到另一骨骼
	BONE_FLAG_ROTATE                                      // 支持旋转
	BONE_FLAG_TRANSLATE                                   // 支持移动
	BONE_FLAG_VISIBLE                                     // 可见
	BONE_FLAG_ENABLED                                     // 允许操作
	BONE_FLAG_IK                                          // 反向动力学
	BONE_FLAG_0X0040                                      //
	BONE_FLAG_LOCAL_ASSIGN                                // 本地付与. 0=用户变形/IK/多重付与, 1=父骨骼的本地变形
	BONE_FLAG_ROTATE_ASSIGN                               // 旋转付与. 随着付与骨旋转.
	BONE_FLAG_TRANSLATE_ASSIGN                            // 移动付与. 随着付与骨移动.
	BONE_FLAG_FIXED_AXIS                                  // 固定轴. 限制只能绕着特定轴旋转.
	BONE_FLAG_LOCAL_AXIS                                  // 本地XZ轴指向
	BONE_FLAG_PHYSICAL_AFTER_DEFORM                       // 先计算变形, 后计算物理
	BONE_FLAG_EXTERNAL_PARENT                             // 外部父骨骼
)

type BoneMethod

type BoneMethod uint8
const (
	BDEF1 BoneMethod = iota
	BDEF2
	BDEF4
	SDEF
	QDEF // 数据结构和BDEF4通用
)

type BoneMorphOffset

type BoneMorphOffset struct {
	Bone       int32
	Translate  [3]float32
	RotateQuat [4]float32 // 四元组 (x, y, z, w)
}

type DisplayFrame

type DisplayFrame struct {
	Name   string
	NameEN string

	SpecialFrame uint8 // 0: 普通 1: 特殊

	Elements []DisplayFrameElem
}

DisplayFrame 是骨骼分组, 主要用于界面显示时把同组的骨骼放在一起

type DisplayFrameElem

type DisplayFrameElem struct {
	Type  uint8 // 0:骨骼 1:变形
	Index int32 // 骨骼或变形的索引
}

type FlipMorphOffset

type FlipMorphOffset ProxyMorphOffset
type Header struct {
	Magic              uint32  // "PMX " 0x20584d50
	Version            float32 // 2.0 2.1
	NumBytes           uint8   // 后续字节数, PMX2.0固定为8
	TextEncoding       uint8   // 0:UTF16 1:UTF8
	NumExtraUV         uint8   // 0 ~ 4
	SizeVertexIndex    uint8   // 1,2 或 4
	SizeTextureIndex   uint8   // 1,2 或 4
	SizeMaterialIndex  uint8   // 1,2 或 4
	SizeBoneIndex      uint8   // 1,2 或 4
	SizeMorphIndex     uint8   // 1,2 或 4
	SizeRigidBodyIndex uint8   // 1,2 或 4
}

PMX文件头

type IKLink struct {
	Bone        int32
	AngleLimit  uint8
	MinAngleXyz [3]float32 // 最小角度(弧度角), 适用于 AngleLimit=true
	MaxAngleXyz [3]float32 // 最大角度(弧度角), 适用于 AngleLimit=true
}

type ImpulseMorphOffset

type ImpulseMorphOffset struct {
	RigidBody int32
	Local     uint8      // 0:OFF 1:ON
	Translate [3]float32 // (x, y, z) 速度
	Rotate    [3]float32 // (x, y, z) 扭矩
}

type Joint

type Joint struct {
	Name   string
	NameEN string

	Type JointType // JOINT_TYPE_*

	RigidBodyA int32 // 相关刚体A, -1为不相关
	RigidBodyB int32 // 相关刚体B, -1为不相关

	Position [3]float32 // (x,y,z) 位置
	Rotation [3]float32 // (x,y,z) 旋转 (弧度角)

	MinPosition [3]float32 // (x,y,z) 移动下限
	MaxPosition [3]float32 // (x,y,z) 移动上限
	MinRotation [3]float32 // (x,y,z) 旋转下限 (弧度角)
	MaxRotation [3]float32 // (x,y,z) 旋转上限 (弧度角)

	K1 [3]float32 // (x,y,z) 弹簧移动常数
	K2 [3]float32 // (x,y,z) 弹簧旋转常数
}

刚体物理的连接点

type JointType

type JointType uint8
const (
	JOINT_TYPE_SPRING_6DOF JointType = iota // 2.0 带弹簧的 6DOF (Bullet 的 btGeneric6DofSpringConstraint)
	JOINT_TYPE_6DOF                         // 2.1 带弹簧的 6DOF,禁用弹簧常数 (Bullet 的 btGeneric6DofConstraint)
	JOINT_TYPE_P2P                          // 2.1 (Bullet 的 btPoint2PointConstraint)
	JOINT_TYPE_CONETWIST                    // 2.1 (Bullet 的 btConeTwistConstraint)
	JOINT_TYPE_SLIDER                       // 2.1 (Bullet 的 btSliderConstraint)
	JOINT_TYPE_HINGE                        // 2.1 (Bullet 的 btHingeConstraint)
)

type Material

type Material struct {
	Name     string
	NameEN   string
	Diffuse  [4]float32 // RGBA
	Specular [4]float32 // RGB + 系数
	Ambient  [3]float32 // RGB

	Flags MaterialFlags

	EdgeColor [4]float32
	EdgeSize  float32

	Texture   int32
	SpTexture int32 // 环境高光纹理 (应该是2次元模型那种头发高光)
	SpMode    uint8 // 0:无效 1:乘法(sph) 2:加法(spa) 3:子纹理(UV参照追加UV1的x,y进行通常纹理绘制)

	ShareToon   uint8 // 0:独立 1:共享
	ToonTexture int32 // 共享模式的 0~9 对应 toon01~toon10, 独立模型用模型里的纹理

	Comment  string
	NumVerts int32 // 材质对应的顶点数, 一定是3的倍数. 所有材质的顶点数加起来等于模型的顶点数.
}

材质

type MaterialFlags

type MaterialFlags uint8
const (
	MATERIAL_FLAG_DOUBLESIDE MaterialFlags = 1 << iota
	MATERIAL_FLAG_GROUNDSHADOW
	MATERIAL_FLAG_SELFSHADOWMAP
	MATERIAL_FLAG_SELFSHADOW
	MATERIAL_FLAG_DRAWEDGE
	MATERIAL_FLAG_VERTEXCOLOR // 2.1
	MATERIAL_FLAG_DRAWPOINT   // 2.1
	MATERIAL_FLAG_DRAWLINE    // 2.1
)

type MaterialMorphOffset

type MaterialMorphOffset struct {
	Material    int32 // -1 表示全部材质
	Addition    uint8 // true用加法. false用乘法 (计算方式: 绘制值=材质值x乘法值+加法值)
	Diffuse     [4]float32
	Specular    [4]float32
	Ambient     [3]float32
	EdgeColor   [4]float32
	EdgeSize    float32
	Texture     [4]float32
	SpTexture   [4]float32
	ToonTexture [4]float32
}

type Morph

type Morph struct {
	Name   string
	NameEN string

	Panel MorphPanel // MORPH_PANEL_*
	Type  MorphType  // MORPH_TYPE_*

	// 为了便于使用, 我们为每种类型单独定义其中一个数组. 实际只有其中一个有数据, 不能混用.
	PositionMorphOffsets []PositionMorphOffset
	UVMorphOffsets       []UVMorphOffset
	BoneMorphOffsets     []BoneMorphOffset
	MaterialMorphOffsets []MaterialMorphOffset
	ProxyMorphOffsets    []ProxyMorphOffset
	FlipMorphOffsets     []FlipMorphOffset
	ImpulseMorphOffsets  []ImpulseMorphOffset
}

变形动画

type MorphPanel

type MorphPanel uint8

Morph在mmd软件中的分组. 主要是便于操作, 对模型本身意义不大.

const (
	MORPH_PANEL_0        MorphPanel = iota //
	MORPH_PANEL_1_BROW                     // 1:眉(左下)
	MORPH_PANEL_2_EYE                      // 2:目(左上)
	MORPH_PANEL_3_MOUTH                    // 3:口(右上)
	MORPH_PANEL_4_OTHERS                   // 4:其他(右下)
)

type MorphType

type MorphType uint8
const (
	MORPH_TYPE_PROXY MorphType = iota // MMD 里的组合变形
	MORPH_TYPE_POSITION
	MORPH_TYPE_BONE
	MORPH_TYPE_UV
	MORPH_TYPE_UV1
	MORPH_TYPE_UV2
	MORPH_TYPE_UV3
	MORPH_TYPE_UV4
	MORPH_TYPE_MATERIAL
	MORPH_TYPE_FLIP    // 2.1
	MORPH_TYPE_IMPULSE // 2.1
)

type PMX

type PMX struct {
	Header Header

	Name          string
	NameEN        string
	Description   string
	DescriptionEN string

	Vertices      []Vertex
	Faces         []uint32 // 3点1面
	Textures      []string
	Materials     []Material
	Bones         []Bone // 骨骼
	Morphs        []Morph
	DisplayFrames []DisplayFrame
	RigidBodies   []RigidBody
	Joints        []Joint // 连接两个刚体的关节 (注意Joint不是骨骼的关节)
	SoftBodies    []SoftBody
}

PMX模型

func Decode

func Decode(r io.Reader) (pm *PMX, err error)

type PositionMorphOffset

type PositionMorphOffset struct {
	Vertex int32
	Offset [3]float32
}

type ProxyMorphOffset

type ProxyMorphOffset struct {
	Morph int32
	Frac  float32
}

type RigidBody

type RigidBody struct {
	Name   string
	NameEN string

	Bone int32 // 关联的骨骼. -1表示不关联

	Group             uint8  // 分组
	NonCollisionGroup uint16 // PE里的"非冲突group"掩码

	Shape    RigidShape // RIGID_SHAPE_*
	Size     [3]float32 // (x,y,z) 尺寸
	Position [3]float32 // (x,y,z) 位置
	Rotation [3]float32 // (x,y,z) 旋转 (弧度角)

	Mass             float32 // 物理量: 质量
	TranslateDamping float32 // 物理量: 移动衰减 attenuation
	RotateDamping    float32 // 物理量: 旋转衰减
	Repulsion        float32 // 物理量: 排斥力
	Friction         float32 // 物理量: 摩檫力

	Physical RigidPhysical // RIGID_PHYSICAL_*

}

刚体

type RigidPhysical

type RigidPhysical uint8
const (
	RIGID_PHYSICAL_BONE         RigidPhysical = iota // 静态绑到骨骼(仅碰撞)
	RIGID_PHYSICAL_DYNAMIC                           // 动态物理演算(重力)
	RIGID_PHYSICAL_DYNAMIC_BONE                      // 动态物理演算(重力) + 绑骨骼
)

type RigidShape

type RigidShape uint8
const (
	RIGID_SHAPE_SPHERE  RigidShape = iota // 球
	RIGID_SHAPE_BOX                       // 盒
	RIGID_SHAPE_CAPSULE                   // 胶囊
)

type SoftBody

type SoftBody struct {
	Name              string
	NameEN            string
	Shape             SoftBodyShape
	Material          int32  // 材质
	Group             uint8  // 分组
	NonCollisionGroup uint16 // PE里的"非冲突group"掩码
	Flags             SoftBodyFlags
	BLinkDistance     int32
	NumCluster        int32
	TotalMass         float32
	CollisionMargin   float32
	AeroModel         SoftBodyAeroModel

	Config struct {
		VCF float32
		DP  float32
		DG  float32
		LF  float32
		PR  float32
		VC  float32
		DF  float32
		MT  float32
		CHR float32
		KHR float32
		SHR float32
		AHR float32
	}

	Cluster struct {
		SRHR_CL    float32
		SKHR_CL    float32
		SSHR_CL    float32
		SR_SPLT_CL float32
		SK_SPLT_CL float32
		SS_SPLT_CL float32
	}

	Iteration struct {
		V_IT int32
		P_IT int32
		D_IT int32
		C_IT int32
	}

	// 物理材料系数
	PhyMaterial struct {
		LST float32
		AST float32
		VST float32
	}

	AnchorRigidBodies []AnchorRigidBody
	PinVertices       []int32
}

软体. PMX 2.1

type SoftBodyAeroModel

type SoftBodyAeroModel int32
const (
	SOFTBODY_AERO_MODEL_V_POINT SoftBodyAeroModel = iota
	SOFTBODY_AERO_MODEL_V_TWOSIDED
	SOFTBODY_AERO_MODEL_V_ONESIDED
	SOFTBODY_AERO_MODEL_F_TWOSIDED
	SOFTBODY_AERO_MODEL_F_ONESIDED
)

type SoftBodyFlags

type SoftBodyFlags uint8
const (
	SOFTBODY_FLAG_B_LINK SoftBodyFlags = iota
	SOFTBODY_FLAG_CLUSTER
	SOFTBODY_FLAG_LINK_CROSS
)

type SoftBodyShape

type SoftBodyShape uint8
const (
	SOFTBODY_SHAPE_TRIMESH SoftBodyShape = iota
	SOFTBODY_SHAPE_ROPE
)

type UVMorphOffset

type UVMorphOffset struct {
	Vertex int32
	Offset [4]float32 // MORPH_TYPE_UV 只用到x和y
}

type Vertex

type Vertex struct {
	Position [3]float32
	Normal   [3]float32
	UV       [2]float32
	UV1      [4]float32
	UV2      [4]float32
	UV3      [4]float32
	UV4      [4]float32

	BoneMethod BoneMethod // BDEF1, BDEF2, BDEF4, SDEF
	Bones      [4]int32
	Weights    [4]float32

	SDEF_C  [3]float32
	SDEF_R0 [3]float32
	SDEF_R1 [3]float32

	EdgeFrac float32 // 材质描边倍率
}

顶点

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL