Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/vrm-c/UniVRM into suppres…
Browse files Browse the repository at this point in the history
…sShaderCompileError
  • Loading branch information
Santarh committed Jul 4, 2024
2 parents 472b2de + 8ea82c4 commit e283f5a
Show file tree
Hide file tree
Showing 90 changed files with 2,474 additions and 579 deletions.
23 changes: 11 additions & 12 deletions .github/ISSUE_TEMPLATE/------bug-report-ja--.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
---
name: バグ報告 (Bug report(ja))
about: 改善のためのレポートを作成します
title: ''
labels: 'bug'
assignees: ''

title: ""
labels: "bug"
assignees: ""
---

## 環境情報

- UniVRM version: `0.81.0`
- Unity version: `Unity-2019.4`
- OS: `Windows 10`
- UniVRM version: `0.123.0`
- Unity version: `Unity-2021.3`
- OS: `Windows 11`

## バグについて

* バグの内容
* ConsoleLog
* スクリーンショット
* 再現方法
* エラーの発生するファイル(ここに貼り付けても差し支えの無いもの)
- バグの内容
- ConsoleLog
- スクリーンショット
- 再現方法
- エラーの発生するファイル(ここに貼り付けても差し支えの無いもの)
5 changes: 2 additions & 3 deletions .github/ISSUE_TEMPLATE/-----feature-request.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
name: 機能追加 Feature request
about: 機能追加要望 Suggest an idea for this project
title: ''
assignees: ''

title: ""
assignees: ""
---
23 changes: 11 additions & 12 deletions .github/ISSUE_TEMPLATE/bug-report-------en--.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: 'bug'
assignees: ''

title: ""
labels: "bug"
assignees: ""
---

## Environments (please complete the following information):

- UniVRM version: `0.81.0`
- Unity version: `Unity-2019.4`
- OS: `Windows 10`
- UniVRM version: `0.123.0`
- Unity version: `Unity-2021.3`
- OS: `Windows 11`

## Describe the bug

* A clear and concise description of what the bug is.
* ConsoleLog
* ScreenShot
* Reproduction procedure
* File that causes an error (those that can be pasted here)
- A clear and concise description of what the bug is.
- ConsoleLog
- ScreenShot
- Reproduction procedure
- File that causes an error (those that can be pasted here)
7 changes: 6 additions & 1 deletion .github/workflows/close-expired-issues.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
name: Expired Issues Closure

on:
workflow_dispatch:
schedule:
- cron: 0 5 * * *

permissions:
issues: write
pull-requests: write

jobs:
cycle-weekly-close:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Close expired "stale" issues
uses: piroor/close-expired-issues-based-on-label@master
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/label_checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Breaking changes label checker

on:
pull_request:
types:
- synchronize
- labeled
- unlabeled
- opened
- reopened

permissions:
statuses: write

jobs:
check-label:
runs-on: ubuntu-latest
name: Breaking changes label checker
steps:
- name: Failed if not labeled
if: "!(contains(github.event.pull_request.labels.*.name, 'Breaking changes') || contains(github.event.pull_request.labels.*.name, 'Non breaking changes'))"
run: |
echo "::error::Please label \"Breaking changes\" or \"Non breaking changes\"."
exit 1
3 changes: 2 additions & 1 deletion Assets/UniGLTF/Editor/UniGLTF.Editor.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"GUID:8d76e605759c3f64a957d63ef96ada7c",
"GUID:da3e51d19d51a544fa14d43fee843098",
"GUID:7da8a75dcade2144aab699032d7d7987",
"GUID:1cd941934d098654fa21a13f28346412"
"GUID:1cd941934d098654fa21a13f28346412",
"GUID:b7aa47b240b57de44a4b2021c143c9bf"
],
"includePlatforms": [
"Editor"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public IEnumerable<Validation> Validate(GameObject ExportRoot)
if (info.Materials.Take(info.Mesh.subMeshCount).Any(x => x == null))
{
// material に null が含まれる(unity で magenta になっているはず)
yield return Validation.Error(Messages.MATERIALS_CONTAINS_NULL.Msg(), ValidationContext.Create(info.Renderers[0].Item1));
yield return Validation.Warning(Messages.MATERIALS_CONTAINS_NULL.Msg(), ValidationContext.Create(info.Renderers[0].Item1));
}
}

Expand Down
61 changes: 38 additions & 23 deletions Assets/UniGLTF/Editor/UniGLTF/Validation/HumanoidValidator.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UniGLTF.M17N;
Expand All @@ -21,6 +22,10 @@ public enum ValidationMessages
[LangMsg(Languages.en, "No Animator in ExportRoot")]
NO_ANIMATOR,

[LangMsg(Languages.ja, "ExportRootに Animator と Humanoid がありません")]
[LangMsg(Languages.en, "No Animator and Humanoid in ExportRoot")]
NO_HUMANOID,

[LangMsg(Languages.ja, "Z+ 向きにしてください")]
[LangMsg(Languages.en, "The model needs to face the positive Z-axis")]
FACE_Z_POSITIVE_DIRECTION,
Expand Down Expand Up @@ -126,34 +131,44 @@ public static IEnumerable<Validation> Validate_TPose(GameObject ExportRoot)
//
// animator
//
var animator = ExportRoot.GetComponent<Animator>();
if (animator == null)
{
yield return Validation.Critical(ValidationMessages.NO_ANIMATOR.Msg());
yield break;
}
Func<HumanBodyBones, Transform> getBoneTransform = null;

// avatar
var avatar = animator.avatar;
if (avatar == null)
if (ExportRoot.GetComponent<UniHumanoid.Humanoid>() is UniHumanoid.Humanoid humanoid)
{
yield return Validation.Critical(ValidationMessages.NO_AVATAR_IN_ANIMATOR.Msg());
yield break;
getBoneTransform = humanoid.GetBoneTransform;
}
if (!avatar.isValid)
else if (ExportRoot.GetComponent<Animator>() is Animator animator)
{
yield return Validation.Critical(ValidationMessages.AVATAR_IS_NOT_VALID.Msg());
yield break;
getBoneTransform = animator.GetBoneTransform;

// avatar
var avatar = animator.avatar;
if (avatar == null)
{
yield return Validation.Critical(ValidationMessages.NO_AVATAR_IN_ANIMATOR.Msg());
yield break;
}
if (!avatar.isValid)
{
yield return Validation.Critical(ValidationMessages.AVATAR_IS_NOT_VALID.Msg());
yield break;
}
if (!avatar.isHuman)
{
yield return Validation.Critical(ValidationMessages.AVATAR_IS_NOT_HUMANOID.Msg());
yield break;
}
}
if (!avatar.isHuman)
else
{
yield return Validation.Critical(ValidationMessages.AVATAR_IS_NOT_HUMANOID.Msg());
yield return Validation.Critical(ValidationMessages.NO_HUMANOID.Msg());
yield break;
}

// direction
{
var l = animator.GetBoneTransform(HumanBodyBones.LeftUpperLeg);
var r = animator.GetBoneTransform(HumanBodyBones.RightUpperLeg);
var l = getBoneTransform(HumanBodyBones.LeftUpperLeg);
var r = getBoneTransform(HumanBodyBones.RightUpperLeg);
var f = GetForward(l, r);
if (Vector3.Dot(f, Vector3.forward) < 0.8f)
{
Expand All @@ -163,18 +178,18 @@ public static IEnumerable<Validation> Validate_TPose(GameObject ExportRoot)
}

{
var lu = animator.GetBoneTransform(HumanBodyBones.LeftUpperArm);
var ll = animator.GetBoneTransform(HumanBodyBones.LeftLowerArm);
var ru = animator.GetBoneTransform(HumanBodyBones.RightUpperArm);
var rl = animator.GetBoneTransform(HumanBodyBones.RightLowerArm);
var lu = getBoneTransform(HumanBodyBones.LeftUpperArm);
var ll = getBoneTransform(HumanBodyBones.LeftLowerArm);
var ru = getBoneTransform(HumanBodyBones.RightUpperArm);
var rl = getBoneTransform(HumanBodyBones.RightLowerArm);
if (Vector3.Dot((ll.position - lu.position).normalized, Vector3.left) < 0.8f
|| Vector3.Dot((rl.position - ru.position).normalized, Vector3.right) < 0.8f)
{
yield return Validation.Error(ValidationMessages.NOT_TPOSE.Msg());
}
}

var jaw = animator.GetBoneTransform(HumanBodyBones.Jaw);
var jaw = getBoneTransform(HumanBodyBones.Jaw);
if (jaw != null)
{
yield return Validation.Warning(ValidationMessages.JAW_BONE_IS_INCLUDED.Msg(), ValidationContext.Create(jaw));
Expand Down
19 changes: 19 additions & 0 deletions Assets/UniGLTF/Runtime/Extensions/IndexExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,24 @@ public static bool HasValidIndex(this int? self)
}
return true;
}

public static bool HasValidIndex(this int? self, int collectionLength)
{
if (!self.HasValue)
{
return false;
}
if (self.Value < 0)
{
// 古いモデルで index の無効値に -1 を使っている場合がある
return false;
}
if (self.Value >= collectionLength)
{
// ついでに上限もチェック
return false;
}
return true;
}
}
}
14 changes: 13 additions & 1 deletion Assets/UniGLTF/Runtime/MeshUtility/MeshAttachInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,19 @@ public void ReplaceMesh(GameObject dst)
if (Bones != null)
{
// recalc bindposes
Mesh.bindposes = Bones.Select(x => x.worldToLocalMatrix * dst.transform.localToWorldMatrix).ToArray();
Mesh.bindposes = Bones.Select(x =>
{
if (x != null)
{
return x.worldToLocalMatrix * dst.transform.localToWorldMatrix;
}
else
{
// ボーンが削除された
return dst.transform.localToWorldMatrix;
}
}
).ToArray();

if (dst.GetComponent<SkinnedMeshRenderer>() is SkinnedMeshRenderer dstRenderer)
{
Expand Down
73 changes: 71 additions & 2 deletions Assets/UniGLTF/Runtime/MeshUtility/MeshExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using UnityEngine;
using System.Linq;
using VRMShaders;
using System;
using System.Collections.Generic;


namespace UniGLTF.MeshUtility
Expand All @@ -23,10 +25,10 @@ public static Mesh GetMesh(this Renderer r)
return null;
}

public static Mesh Copy(this Mesh src, bool copyBlendShape)
public static Mesh Copy(this Mesh src, bool copyBlendShape, string nameSuffix = "(copy)")
{
var dst = new Mesh();
dst.name = src.name + "(copy)";
dst.name = src.name + nameSuffix;
#if UNITY_2017_3_OR_NEWER
dst.indexFormat = src.indexFormat;
#endif
Expand Down Expand Up @@ -108,5 +110,72 @@ public static void ApplyMatrix(this Mesh src, Matrix4x4 m)
}).ToArray();
}
}

class BlendShape
{
public readonly string Name;
public readonly float FrameWeight;
public readonly Vector3[] Vertices;
public readonly Vector3[] Normals;
public readonly Vector3[] Tangents;
public BlendShape(string name, float frameweight,
IEnumerable<Vector3> vertices,
IEnumerable<Vector3> normals,
IEnumerable<Vector3> tangents)
{
Name = name;
FrameWeight = frameweight;
Vertices = vertices.ToArray();
Normals = normals.ToArray();
Tangents = tangents.ToArray();
}

public static BlendShape FromMesh(Mesh mesh, int i, Matrix4x4 m)
{
var blendShapePositions = new Vector3[mesh.vertexCount];
var blendShapeNormals = new Vector3[mesh.vertexCount];
var blendShapeTangents = new Vector3[mesh.vertexCount];
mesh.GetBlendShapeFrameVertices(i, 0, blendShapePositions, blendShapeNormals, blendShapeTangents);
return new BlendShape(
mesh.GetBlendShapeName(i), mesh.GetBlendShapeFrameWeight(i, 0),
blendShapePositions.Select(x => m.MultiplyPoint(x)),
blendShapeNormals.Select(x => m.MultiplyPoint(x)),
blendShapeTangents.Select(x => m.MultiplyPoint(x)));
}
}

public static void ApplyMatrixAlsoBlendShapes(this Mesh src, Matrix4x4 m)
{
src.vertices = src.vertices.Select(x => m.MultiplyPoint(x)).ToArray();
if (src.normals != null && src.normals.Length > 0)
{
src.normals = src.normals.Select(x => m.MultiplyVector(x.normalized)).ToArray();
}
if (src.tangents != null && src.tangents.Length > 0)
{
src.tangents = src.tangents.Select(x =>
{
var t = m.MultiplyVector((Vector3)x);
return new Vector4(t.x, t.y, t.z, x.w);
}).ToArray();
}

var blendshapes = new List<BlendShape>();
for (int i = 0; i < src.blendShapeCount; ++i)
{
blendshapes.Add(BlendShape.FromMesh(src, i, m));
}
src.ClearBlendShapes();
foreach (var blendshape in blendshapes)
{
src.AddBlendShapeFrame(blendshape.Name, blendshape.FrameWeight,
blendshape.Vertices,
// 法線は import / export 対象
blendshape.Normals,
// tangent は import / export の扱いが無い
null
);
}
}
}
}
Loading

0 comments on commit e283f5a

Please sign in to comment.