Skip to content

Commit 55601d5

Browse files
authored
Merge pull request #10 from kirurobo/develop
UniVRM 0.44 に対応させました。
2 parents 4dfdbce + caa85ef commit 55601d5

253 files changed

Lines changed: 7811 additions & 4607 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Assets/UniWinApi/Examples/99_VrmViewerSample/CharacterBehaviour.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,22 @@ public class CharacterBehaviour : MonoBehaviour
99

1010
private float lastBlinkTime = 0f;
1111
private float nextBlinkTime = 0f;
12-
private int blinkBlendShapeIndex = -1;
1312
private int blinkState = 0; // まばたきの状態管理。 0:なし, 1:閉じ中, 2:開き中
1413

1514
private VRMLookAtHead lookAtHead;
1615
private VRMBlendShapeProxy blendShapeProxy;
1716

1817
private GameObject targetObject; // 視線目標オブジェクト
19-
private Transform headTransform; // Head transform
18+
private Transform headTransform; // Head transform
19+
private bool isNewTargetObject = false; // 新規に目標オブジェクトを作成したらtrue
2020

2121
// Use this for initialization
2222
void Start()
2323
{
2424
if (!targetObject)
2525
{
2626
targetObject = new GameObject("LookAtTarget");
27+
isNewTargetObject = true;
2728
}
2829

2930
lookAtHead = GetComponent<VRMLookAtHead>();
@@ -34,14 +35,25 @@ void Start()
3435
lookAtHead.Target = targetObject.transform;
3536
lookAtHead.UpdateType = UpdateType.LateUpdate;
3637

37-
headTransform = lookAtHead.Head.Transform;
38+
headTransform = lookAtHead.Head;
3839
}
3940
if (!headTransform)
4041
{
4142
headTransform = this.transform;
4243
}
4344
}
4445

46+
/// <summary>
47+
/// Destroy created target object
48+
/// </summary>
49+
void OnDestroy()
50+
{
51+
if (isNewTargetObject)
52+
{
53+
GameObject.Destroy(targetObject);
54+
}
55+
}
56+
4557
/// <summary>
4658
/// 毎フレーム呼ばれる
4759
/// </summary>

Assets/UniWinApi/Examples/99_VrmViewerSample/VrmSample.cs

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ void Start () {
5050
audioSource = FindObjectOfType<AudioSource>();
5151
}
5252

53-
// Load the initial motion.
54-
LoadMotion(Application.streamingAssetsPath + "/default_bvh.txt");
55-
5653
// Load the initial model.
5754
string[] cmdArgs = System.Environment.GetCommandLineArgs();
5855
if (cmdArgs.Length > 1)
@@ -63,8 +60,11 @@ void Start () {
6360
LoadModel(Application.streamingAssetsPath + "/default_vrm.vrm");
6461
}
6562

63+
// Load the initial motion.
64+
LoadMotion(Application.streamingAssetsPath + "/default_bvh.txt");
65+
6666
// Initialize window manager
67-
windowController =FindObjectOfType<WindowController>();
67+
windowController = FindObjectOfType<WindowController>();
6868
if (windowController)
6969
{
7070
// Add a file drop handler.
@@ -172,27 +172,44 @@ private void SetMotion(HumanPoseTransfer motion, HumanPoseTransfer model, VRMMet
172172
/// <param name="path"></param>
173173
private void LoadMotion(string path)
174174
{
175-
ImporterContext context = new ImporterContext
176-
{
177-
Path = path
178-
};
175+
if (!File.Exists(path)) return;
176+
177+
GameObject newMotionObject = null;
179178

180179
try
181180
{
181+
BvhImporterContext context = new BvhImporterContext();
182+
//Debug.Log("Loading motion : " + path);
182183

183-
BvhImporter.Import(context);
184-
motion = context.Root.GetComponent<HumanPoseTransfer>();
185-
motion.GetComponent<Renderer>().enabled = false;
184+
context.Parse(path);
185+
context.Load();
186+
newMotionObject = context.Root;
187+
188+
// Hide the motion model
189+
Renderer renderer = newMotionObject.GetComponent<Renderer>();
190+
if (renderer)
191+
{
192+
renderer.enabled = false;
193+
}
186194

187-
SetMotion(motion, model, meta);
188195
} catch (Exception ex)
189196
{
190197
if (uiController) uiController.SetWarning("Motion load failed.");
198+
Debug.LogError("Failed loading " + path);
191199
Debug.LogError(ex);
192200
return;
193201
}
194-
finally
202+
203+
if (newMotionObject)
195204
{
205+
if (motion)
206+
{
207+
GameObject.Destroy(motion.gameObject);
208+
}
209+
210+
motion = newMotionObject.GetComponent<HumanPoseTransfer>();
211+
SetMotion(motion, model, meta);
212+
196213
// Play loaded audio if available
197214
if (audioSource && audioSource.clip && audioSource.clip.loadState == AudioDataLoadState.Loaded)
198215
{
@@ -209,35 +226,36 @@ private void LoadMotion(string path)
209226
private void LoadModel(string path)
210227
{
211228
if (!File.Exists(path)) return;
212-
213-
GameObject newModel = null;
229+
GameObject newModelObject = null;
214230

215231
try
216232
{
217233
// Load from a VRM file.
218-
byte[] bytes = File.ReadAllBytes(path);
219-
context = new VRMImporterContext(UniGLTF.UnityPath.FromFullpath(path));
220-
context.ParseGlb(bytes);
221-
VRMImporter.LoadFromBytes(context);
234+
context = new VRMImporterContext();
235+
//Debug.Log("Loading model : " + path);
222236

223-
newModel = context.Root;
237+
context.Load(path);
238+
newModelObject = context.Root;
224239
meta = context.ReadMeta();
240+
241+
context.ShowMeshes();
225242
}
226243
catch (Exception ex)
227244
{
228245
if (uiController) uiController.SetWarning("Model load failed.");
246+
Debug.LogError("Failed loading " + path);
229247
Debug.LogError(ex);
230248
return;
231249
}
232250

233-
if (model)
251+
if (newModelObject)
234252
{
235-
GameObject.Destroy(model.gameObject);
236-
}
253+
if (model)
254+
{
255+
GameObject.Destroy(model.gameObject);
256+
}
237257

238-
if (newModel)
239-
{
240-
model = newModel.AddComponent<HumanPoseTransfer>();
258+
model = newModelObject.AddComponent<HumanPoseTransfer>();
241259
SetMotion(motion, model, meta);
242260

243261
model.gameObject.AddComponent<CharacterBehaviour>();

Assets/UniWinApi/Examples/99_VrmViewerSample/VrmViewerSample.unity

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ RenderSettings:
2020
m_FogDensity: 0.01
2121
m_LinearFogStart: 0
2222
m_LinearFogEnd: 300
23-
m_AmbientSkyColor: {r: 1, g: 1, b: 1, a: 1}
23+
m_AmbientSkyColor: {r: 0.8, g: 0.8, b: 0.8, a: 1}
2424
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
2525
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
2626
m_AmbientIntensity: 1
@@ -38,7 +38,7 @@ RenderSettings:
3838
m_ReflectionIntensity: 1
3939
m_CustomReflection: {fileID: 0}
4040
m_Sun: {fileID: 0}
41-
m_IndirectSpecularColor: {r: 0.4513998, g: 0.5008927, b: 0.5723166, a: 1}
41+
m_IndirectSpecularColor: {r: 0.44657815, g: 0.49641407, b: 0.57481676, a: 1}
4242
--- !u!157 &3
4343
LightmapSettings:
4444
m_ObjectHideFlags: 0
@@ -51,7 +51,7 @@ LightmapSettings:
5151
m_AlbedoBoost: 1
5252
m_TemporalCoherenceThreshold: 1
5353
m_EnvironmentLightingMode: 0
54-
m_EnableBakedLightmaps: 1
54+
m_EnableBakedLightmaps: 0
5555
m_EnableRealtimeLightmaps: 1
5656
m_LightmapEditorSettings:
5757
serializedVersion: 8
@@ -71,7 +71,7 @@ LightmapSettings:
7171
m_FinalGatherFiltering: 1
7272
m_FinalGatherRayCount: 256
7373
m_ReflectionCompression: 2
74-
m_MixedBakeMode: 2
74+
m_MixedBakeMode: 0
7575
m_BakeBackend: 0
7676
m_PVRSampling: 1
7777
m_PVRDirectSampleCount: 32
@@ -89,7 +89,7 @@ LightmapSettings:
8989
m_PVRFilteringAtrousPositionSigmaIndirect: 2
9090
m_PVRFilteringAtrousPositionSigmaAO: 1
9191
m_LightingDataAsset: {fileID: 0}
92-
m_ShadowMaskMode: 2
92+
m_ShadowMaskMode: 0
9393
--- !u!196 &4
9494
NavMeshSettings:
9595
serializedVersion: 2
@@ -546,7 +546,7 @@ GameObject:
546546
- component: {fileID: 339774399}
547547
- component: {fileID: 339774398}
548548
m_Layer: 5
549-
m_Name: Panel
549+
m_Name: MenuPanel
550550
m_TagString: Untagged
551551
m_Icon: {fileID: 0}
552552
m_NavMeshLayer: 0
@@ -2385,7 +2385,7 @@ Light:
23852385
m_Enabled: 1
23862386
serializedVersion: 8
23872387
m_Type: 1
2388-
m_Color: {r: 1, g: 1, b: 1, a: 1}
2388+
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
23892389
m_Intensity: 0.5
23902390
m_Range: 10
23912391
m_SpotAngle: 30
@@ -2418,13 +2418,13 @@ Transform:
24182418
m_PrefabParentObject: {fileID: 0}
24192419
m_PrefabInternal: {fileID: 0}
24202420
m_GameObject: {fileID: 2141451816}
2421-
m_LocalRotation: {x: 0.25660488, y: 0.12607859, z: -0.03378266, w: 0.9576622}
2421+
m_LocalRotation: {x: 0.76328206, y: -0.3904523, z: -0.024150606, w: 0.5141636}
24222422
m_LocalPosition: {x: -1.5, y: 4, z: -6}
24232423
m_LocalScale: {x: 1, y: 1, z: 1}
24242424
m_Children: []
24252425
m_Father: {fileID: 1629460662}
24262426
m_RootOrder: 0
2427-
m_LocalEulerAnglesHint: {x: 30, y: 15, z: 0}
2427+
m_LocalEulerAnglesHint: {x: 130, y: 43, z: 75}
24282428
--- !u!114 &2141451819
24292429
MonoBehaviour:
24302430
m_ObjectHideFlags: 0

Assets/UniWinApi/Examples/Utils/CameraController.cs

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,39 @@ public enum ZoomMode
3737

3838
public Transform centerTransform; // 回転中心
3939

40-
Vector3 rotation;
41-
Vector3 translation;
40+
internal Vector3 rotation;
41+
internal Vector3 translation;
4242

4343
[SerializeField]
44-
float distance;
44+
internal float distance;
4545

46-
Vector3 relativePosition;
47-
Quaternion relativeRotation;
48-
float originalDistance;
49-
float originalFieldOfView;
50-
float dolly;
51-
float zoom;
46+
internal Vector3 relativePosition;
47+
internal Quaternion relativeRotation;
48+
internal float originalDistance;
49+
internal float originalFieldOfView;
50+
internal float dolly;
51+
internal float zoom;
5252

53-
Camera currentCamera;
53+
internal Camera currentCamera;
5454

5555
void Start()
56+
{
57+
Initialize();
58+
}
59+
60+
void Update()
61+
{
62+
if (!currentCamera.isActiveAndEnabled) return;
63+
if (!Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.RightShift))
64+
{
65+
HandleMouse();
66+
}
67+
}
68+
69+
/// <summary>
70+
/// Initialize
71+
/// </summary>
72+
internal void Initialize()
5673
{
5774
if (!centerTransform)
5875
{
@@ -98,7 +115,7 @@ public void ResetTransform()
98115
/// <summary>
99116
/// Apply rotation and translation
100117
/// </summary>
101-
private void UpdateTransform()
118+
internal void UpdateTransform()
102119
{
103120
Quaternion rot = Quaternion.Euler(rotation);
104121
transform.rotation = rot;
@@ -107,16 +124,7 @@ private void UpdateTransform()
107124
currentCamera.fieldOfView = Mathf.Pow(10f, zoom);
108125
}
109126

110-
void Update()
111-
{
112-
if (!currentCamera.isActiveAndEnabled) return;
113-
if (!Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.RightShift))
114-
{
115-
HandleMouse();
116-
}
117-
}
118-
119-
internal void HandleMouse()
127+
internal virtual void HandleMouse()
120128
{
121129
if (Input.GetMouseButton(1))
122130
{

Assets/UniWinApi/Examples/Utils/LightController.cs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,48 @@
33
using UnityEngine;
44

55
public class LightController : CameraController {
6-
6+
77
// Update is called once per frame
88
void Update () {
9+
// [Shift]が押されていれば、照明の回転を行う
910
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
1011
{
1112
HandleMouse();
1213
}
1314
}
15+
16+
internal override void HandleMouse()
17+
{
18+
if (Input.GetMouseButton(1))
19+
{
20+
// 右ボタンドラッグで照明を回転
21+
if ((axes & RotationAxes.Yaw) > RotationAxes.None)
22+
{
23+
rotation.y += Input.GetAxis("Mouse X") * sensitivityX;
24+
rotation.y = ClampAngle(rotation.y, minimumAngles.y, maximumAngles.y);
25+
}
26+
if ((axes & RotationAxes.Pitch) > RotationAxes.None)
27+
{
28+
rotation.x -= Input.GetAxis("Mouse Y") * sensitivityY;
29+
rotation.x = ClampAngle(rotation.x, minimumAngles.x, maximumAngles.x);
30+
}
31+
UpdateTransform();
32+
}
33+
else
34+
{
35+
// ホイールで環境光の明るさを増減
36+
float wheelDelta = Input.GetAxis("Mouse ScrollWheel") * wheelSensitivity;
37+
38+
if (wheelDelta != 0f)
39+
{
40+
//float intensity = RenderSettings.ambientIntensity;
41+
//Mathf.Clamp(intensity - wheelDelta, 0f, 8f);
42+
//RenderSettings.ambientIntensity = intensity;
43+
Color color = RenderSettings.ambientLight;
44+
float v = Mathf.Clamp(color.r + wheelDelta, 0f, 1f);
45+
color.r = color.g = color.b = v;
46+
RenderSettings.ambientLight = color;
47+
}
48+
}
49+
}
1450
}

0 commit comments

Comments
 (0)