Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add VRM spring bone support
Browse files Browse the repository at this point in the history
poi-vrc committed Dec 14, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent ebe693a commit 88d5047
Showing 12 changed files with 1,206 additions and 7 deletions.
53 changes: 53 additions & 0 deletions .github/unity-project/Packages/manifest-vrm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"dependencies": {
"com.unity.burst": "1.4.11",
"com.unity.collab-proxy": "1.6.0",
"com.unity.ide.rider": "1.2.1",
"com.unity.ide.visualstudio": "2.0.9",
"com.unity.ide.vscode": "1.2.3",
"com.unity.mathematics": "1.2.6",
"com.unity.nuget.newtonsoft-json": "3.2.1",
"com.unity.test-framework": "1.1.27",
"com.unity.testtools.codecoverage": "1.2.4",
"com.unity.textmeshpro": "2.1.6",
"com.unity.timeline": "1.2.18",
"com.unity.ugui": "1.0.0",
"com.unity.xr.oculus.standalone": "2.38.4",
"com.unity.xr.openvr.standalone": "2.0.5",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"com.unity.modules.animation": "1.0.0",
"com.unity.modules.assetbundle": "1.0.0",
"com.unity.modules.audio": "1.0.0",
"com.unity.modules.cloth": "1.0.0",
"com.unity.modules.director": "1.0.0",
"com.unity.modules.imageconversion": "1.0.0",
"com.unity.modules.imgui": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.particlesystem": "1.0.0",
"com.unity.modules.physics": "1.0.0",
"com.unity.modules.physics2d": "1.0.0",
"com.unity.modules.screencapture": "1.0.0",
"com.unity.modules.terrain": "1.0.0",
"com.unity.modules.terrainphysics": "1.0.0",
"com.unity.modules.tilemap": "1.0.0",
"com.unity.modules.ui": "1.0.0",
"com.unity.modules.uielements": "1.0.0",
"com.unity.modules.umbra": "1.0.0",
"com.unity.modules.unityanalytics": "1.0.0",
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.modules.unitywebrequestassetbundle": "1.0.0",
"com.unity.modules.unitywebrequestaudio": "1.0.0",
"com.unity.modules.unitywebrequesttexture": "1.0.0",
"com.unity.modules.unitywebrequestwww": "1.0.0",
"com.unity.modules.vehicles": "1.0.0",
"com.unity.modules.video": "1.0.0",
"com.unity.modules.vr": "1.0.0",
"com.unity.modules.wind": "1.0.0",
"com.unity.modules.xr": "1.0.0",
"com.vrmc.vrmshaders": "https://github.com/vrm-c/UniVRM.git?path=/Assets/VRMShaders#v0.116.0",
"com.vrmc.gltf": "https://github.com/vrm-c/UniVRM.git?path=/Assets/UniGLTF#v0.116.0",
"com.vrmc.univrm": "https://github.com/vrm-c/UniVRM.git?path=/Assets/VRM#v0.116.0",
"com.vrmc.vrm": "https://github.com/vrm-c/UniVRM.git?path=/Assets/VRM10#v0.116.0"
}
}
17 changes: 12 additions & 5 deletions .github/workflows/unity-tests.yml
Original file line number Diff line number Diff line change
@@ -9,15 +9,18 @@ on:

jobs:
build:
name: Build and Test (${{ matrix.unity-version }}${{ matrix.import-vrcsdk && ', VRC' || '' }}${{ matrix.import-dynbone && ', DynBone' || '' }})
name: Build and Test (${{ matrix.unity-version }}${{ matrix.import-vrcsdk && ', VRC' || '' }}${{ matrix.import-dynbone && ', DynBone' || '' }}${{ matrix.import-univrm && ', VRM' || '' }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
unity-version: ['2019.4.31f1', '2021.3.33f1', '2022.3.6f1', '2023.2.2f1']
import-vrcsdk: [false, true]
import-dynbone: [false, true]
import-univrm: [false, true]
exclude:
- unity-version: "2019.4.31f1"
import-univrm: true
- unity-version: "2021.3.33f1"
import-vrcsdk: true
- unity-version: "2023.2.2f1"
@@ -46,9 +49,13 @@ jobs:
- uses: actions/cache@v3
with:
path: Library
key: Library-${{ matrix.unity-version }}-${{ matrix.import-vrcsdk }}-${{ matrix.import-dynbone }}-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }}
key: Library-${{ matrix.unity-version }}-${{ matrix.import-vrcsdk }}-${{ matrix.import-dynbone }}-${{ matrix.import-univrm }}-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }}
restore-keys: |
Library-${{ matrix.unity-version }}-${{ matrix.import-vrcsdk }}-${{ matrix.import-dynbone }}-
Library-${{ matrix.unity-version }}-${{ matrix.import-vrcsdk }}-${{ matrix.import-dynbone }}-${{ matrix.import-univrm }}-
- name: Use UniVRM manifest
if: matrix.import-univrm
run: mv Packages/manifest-vrm.json Packages/manifest.json

- name: Resolve VPM Project
if: matrix.import-vrcsdk
@@ -84,14 +91,14 @@ jobs:
- uses: actions/upload-artifact@v3
if: always()
with:
name: Test results (${{ matrix.unity-version }}${{ matrix.import-vrcsdk && ', VRC' || '' }}${{ matrix.import-dynbone && ', DynBone' || '' }})
name: Test results (${{ matrix.unity-version }}${{ matrix.import-vrcsdk && ', VRC' || '' }}${{ matrix.import-dynbone && ', DynBone' || '' }}${{ matrix.import-univrm && ', VRM' || '' }})
path: artifacts

# Upload coverage report to GitHub
- uses: actions/upload-artifact@v3
if: always()
with:
name: Coverage results (${{ matrix.unity-version }}${{ matrix.import-vrcsdk && ', VRC' || '' }}${{ matrix.import-dynbone && ', DynBone' || '' }})
name: Coverage results (${{ matrix.unity-version }}${{ matrix.import-vrcsdk && ', VRC' || '' }}${{ matrix.import-dynbone && ', DynBone' || '' }}${{ matrix.import-univrm && ', VRM' || '' }})
path: ${{ steps.tests.outputs.coveragePath }}

# Upload coverage report to Codecov
19 changes: 19 additions & 0 deletions Editor/DKEditorUtils.cs
Original file line number Diff line number Diff line change
@@ -140,6 +140,7 @@ public static List<IDynamicsProxy> ScanDynamics(GameObject obj, bool doNotScanCo
// get the dynbone type
var DynamicBoneType = FindType("DynamicBone");
var PhysBoneType = FindType("VRC.SDK3.Dynamics.PhysBone.Components.VRCPhysBone");
var VRMSpringBoneType = FindType("VRM.VRMSpringBone");

// scan dynbones
if (DynamicBoneType != null)
@@ -169,6 +170,24 @@ public static List<IDynamicsProxy> ScanDynamics(GameObject obj, bool doNotScanCo
}
}

// scan vrmspringbones
if (VRMSpringBoneType != null)
{
var vrmSpringBones = obj.GetComponentsInChildren(VRMSpringBoneType, true);
foreach (var vrmSpringBone in vrmSpringBones)
{
var rootBones = VRMSpringBoneProxy.GetRootBones(vrmSpringBone);
foreach (var rootBone in rootBones)
{
if (doNotScanContainingWearables && IsOriginatedFromAnyWearable(obj.transform, rootBone))
{
continue;
}
dynamicsList.Add(new VRMSpringBoneProxy(vrmSpringBone, rootBone));
}
}
}

return dynamicsList;
}

76 changes: 76 additions & 0 deletions Editor/Proxy/VRMSpringBoneProxy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (c) 2023 chocopoi
*
* This file is part of DressingFramework.
*
* DressingFramework is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* DressingFramework is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with DressingFramework. If not, see <https://www.gnu.org/licenses/>.
*/

using System.Collections.Generic;
using UnityEngine;

namespace Chocopoi.DressingFramework.Proxy
{
internal class VRMSpringBoneProxy : IDynamicsProxy
{
public static readonly System.Type VRMSpringBoneType = DKEditorUtils.FindType("VRM.VRMSpringBone");

private Transform _rootTransform;

public VRMSpringBoneProxy(Component component, Transform rootTransform)
{
Component = component;
_rootTransform = rootTransform;
if (VRMSpringBoneType == null)
{
throw new System.Exception("No VRMSpringBone component is found in this project. It is required to process VRMSpringBone-based dynamics.");
}
}

public static List<Transform> GetRootBones(Component component)
{
return (List<Transform>)VRMSpringBoneType.GetField("RootBones").GetValue(component);
}

public Component Component { get; set; }

public Transform Transform
{
get { return Component.transform; }
}

public GameObject GameObject
{
get { return Component.gameObject; }
}

public Transform RootTransform
{
get { return _rootTransform; }
set
{
var rootBones = GetRootBones(Component);
if (!rootBones.Remove(_rootTransform))
{
Debug.LogWarning("[DressingFramework] The VRM Spring Bone does not have the original root transform. Unable to remove.");
}
rootBones.Add(value);
_rootTransform = value;
}
}

public List<Transform> IgnoreTransforms
{
get
{
Debug.LogWarning("[DressingFramework] VRM Spring Bone does not support IgnoreTransform, but this API was called!");
return new List<Transform>();
}
set { Debug.LogWarning("[DressingFramework] VRM Spring Bone does not support IgnoreTransform, but this API was called!"); }
}
}
}
11 changes: 11 additions & 0 deletions Editor/Proxy/VRMSpringBoneProxy.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion Editor/com.chocopoi.vrc.dressingframework.Editor.asmdef
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "com.chocopoi.vrc.dressingframework.Editor",
"rootNamespace": "",
"references": [
"GUID:dcaf16fd99f37914888e6e13bdf533ea"
],
@@ -12,6 +13,12 @@
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"versionDefines": [
{
"name": "com.vrmc.vrm",
"expression": "0.110.0",
"define": "DK_VRM"
}
],
"noEngineReferences": false
}
12 changes: 12 additions & 0 deletions Tests~/Editor/DKEditorUtilsTest.cs
Original file line number Diff line number Diff line change
@@ -142,6 +142,18 @@ public void ScanDynamics_PhysBone()
#endif
}

[Test]
public void ScanDynamics_VRMSpringBone()
{
#if !DK_VRM
Assert.Pass("UniVRM is not imported, skipping this test");
#else
var root = InstantiateEditorTestPrefab("DKTest_VRMSpringBoneAvatar.prefab");
InstantiateEditorTestPrefab("DKTest_VRMSpringBoneWearable.prefab", root.transform);
AssertScannedDynamics(root);
#endif
}

private class DummyDynamicsProxy : IDynamicsProxy
{
public Component Component { get; set; } = null;

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "com.chocopoi.vrc.dressingframework.Editor.Tests",
"rootNamespace": "",
"references": [
"UnityEngine.TestRunner",
"UnityEditor.TestRunner",
@@ -21,6 +22,12 @@
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [],
"versionDefines": [
{
"name": "com.vrmc.vrm",
"expression": "0.110",
"define": "DK_VRM"
}
],
"noEngineReferences": false
}

0 comments on commit 88d5047

Please sign in to comment.