Exemple #1
0
        private static void RotateShoulderAttachments(WowObject characterWowObject, string attachmentBoneName, string upperArmBoneName, float rotationAngle)
        {
            var shoulderAttachment = characterWowObject.FindBoneByName(attachmentBoneName);
            var upperArm           = characterWowObject.FindBoneByName(upperArmBoneName);

            if (shoulderAttachment != null && upperArm != null)
            {
                var change = new WowVrcFileData.BlendshapeData.BoneData[] { new WowVrcFileData.BlendshapeData.BoneData()
                                                                            {
                                                                                LocalTransform = new WowTransform()
                                                                                {
                                                                                    position = new Vec3(),
                                                                                    rotation = Quat.RotateY(Quat.Create(), rotationAngle),
                                                                                    scale    = new Vec3(1f, 1f, 1f)
                                                                                },
                                                                                Name = upperArmBoneName
                                                                            } };

                foreach (var obj in shoulderAttachment.AttachedWowObjects)
                {
                    foreach (var mesh in obj.Meshes)
                    {
                        var basicBakedBlendshape = BlendShapeUtility.BakeBlendShape(obj.GlobalPosition, mesh.Vertices, characterWowObject.Bones, change, 1f);

                        foreach (var basicBakedBlendshapeElement in basicBakedBlendshape)
                        {
                            mesh.Vertices[basicBakedBlendshapeElement.Key].Position = new Vec3(basicBakedBlendshapeElement.Value.Position.X, basicBakedBlendshapeElement.Value.Position.Y, basicBakedBlendshapeElement.Value.Position.Z);
                            mesh.Vertices[basicBakedBlendshapeElement.Key].Normal   = new Vec3(basicBakedBlendshapeElement.Value.Normal.X, basicBakedBlendshapeElement.Value.Normal.Y, basicBakedBlendshapeElement.Value.Normal.Z);
                        }
                    }
                }
            }
        }
Exemple #2
0
            public void SetLocalDataFromBlendshapeBone(WowBone bone, WowVrcFileData.BlendshapeData.BoneData blendshapeBoneChange, float scale)
            {
                var matrix = Mat4.Identity();

                Vec3 localPosition = bone.LocalPosition;

                localPosition.X += blendshapeBoneChange.LocalTransform.position.X * scale;
                localPosition.Y += blendshapeBoneChange.LocalTransform.position.Y * scale;
                localPosition.Z += blendshapeBoneChange.LocalTransform.position.Z * scale;

                matrix = Mat4.Translate(matrix, localPosition);

                // Поврота и скейла у базовых костей нет, так что учитываем только поврот и скейл из изменений блендшейпа
                matrix = Mat4.Multiply(matrix, Mat4.FromQuat(blendshapeBoneChange.LocalTransform.rotation));
                matrix = Mat4.Scale(matrix, blendshapeBoneChange.LocalTransform.scale);

                LocalMatrix = matrix;
            }