diff --git a/Assets/VRM10/Editor/Components/VRM10Window.cs b/Assets/VRM10/Editor/Components/VRM10Window.cs index 1e7891a62..8bdae96b7 100644 --- a/Assets/VRM10/Editor/Components/VRM10Window.cs +++ b/Assets/VRM10/Editor/Components/VRM10Window.cs @@ -19,7 +19,7 @@ namespace UniVRM10 var window = (VRM10Window)GetWindow(typeof(VRM10Window)); window.titleContent = new GUIContent(WINDOW_TITLE); window.Show(); - window.Root = UnityEditor.Selection.activeTransform.GetComponent(); + window.Root = UnityEditor.Selection.activeTransform?.GetComponent(); } void OnEnable() diff --git a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs index 99d71171d..2cd336bcd 100644 --- a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs +++ b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs @@ -27,19 +27,16 @@ namespace UniVRM10 base.OnEnable(); m_importer = target as VrmScriptedImporter; + m_parser = default; + m_message = default; if (!Vrm10Parser.TryParseOrMigrate(m_importer.assetPath, m_importer.MigrateToVrm1, out Vrm10Parser.Result result, out m_message)) { // error return; } - if (!UniGLTF.Extensions.VRMC_vrm.GltfDeserializer.TryGet(m_parser.GLTF.extensions, out m_vrm)) - { - // error - m_message = "no vrm1"; - m_parser = null; - return; - } - m_model = ModelReader.Read(m_parser); + m_vrm = result.Vrm; + m_parser = result.Parser; + m_model = ModelReader.Read(result.Parser); } enum Tabs diff --git a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs index 1e96fe11c..b1ae1537f 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs @@ -349,10 +349,22 @@ namespace UniVRM10 var src = vrm.LookAt; controller.LookAt.LookAtType = src.Type; controller.LookAt.OffsetFromHead = new Vector3(src.OffsetFromHeadBone[0], src.OffsetFromHeadBone[1], src.OffsetFromHeadBone[2]); - controller.LookAt.HorizontalInner = new CurveMapper(src.RangeMapHorizontalInner.InputMaxValue.Value, src.RangeMapHorizontalInner.OutputScale.Value); - controller.LookAt.HorizontalOuter = new CurveMapper(src.RangeMapHorizontalOuter.InputMaxValue.Value, src.RangeMapHorizontalOuter.OutputScale.Value); - controller.LookAt.VerticalUp = new CurveMapper(src.RangeMapVerticalUp.InputMaxValue.Value, src.RangeMapVerticalUp.OutputScale.Value); - controller.LookAt.VerticalDown = new CurveMapper(src.RangeMapVerticalDown.InputMaxValue.Value, src.RangeMapVerticalDown.OutputScale.Value); + if (src.RangeMapHorizontalInner != null) + { + controller.LookAt.HorizontalInner = new CurveMapper(src.RangeMapHorizontalInner.InputMaxValue.Value, src.RangeMapHorizontalInner.OutputScale.Value); + } + if (src.RangeMapHorizontalOuter != null) + { + controller.LookAt.HorizontalOuter = new CurveMapper(src.RangeMapHorizontalOuter.InputMaxValue.Value, src.RangeMapHorizontalOuter.OutputScale.Value); + } + if (src.RangeMapVerticalUp != null) + { + controller.LookAt.VerticalUp = new CurveMapper(src.RangeMapVerticalUp.InputMaxValue.Value, src.RangeMapVerticalUp.OutputScale.Value); + } + if (src.RangeMapVerticalDown != null) + { + controller.LookAt.VerticalDown = new CurveMapper(src.RangeMapVerticalDown.InputMaxValue.Value, src.RangeMapVerticalDown.OutputScale.Value); + } } // firstPerson @@ -386,66 +398,75 @@ namespace UniVRM10 } // colliderGroup - foreach (var g in gltfVrmSpringBone.ColliderGroups) + if (gltfVrmSpringBone.ColliderGroups != null) { - var colliderGroup = secondary.gameObject.AddComponent(); - controller.SpringBone.ColliderGroups.Add(colliderGroup); - - foreach (var c in g.Colliders) + foreach (var g in gltfVrmSpringBone.ColliderGroups) { - var node = Nodes[c.Node.Value]; + var colliderGroup = secondary.gameObject.AddComponent(); + controller.SpringBone.ColliderGroups.Add(colliderGroup); - var collider = node.gameObject.AddComponent(); - colliderGroup.Colliders.Add(collider); + foreach (var c in g.Colliders) + { + var node = Nodes[c.Node.Value]; - if (c.Shape.Sphere is UniGLTF.Extensions.VRMC_springBone.ColliderShapeSphere sphere) - { - collider.ColliderType = VRM10SpringBoneColliderTypes.Sphere; - collider.Radius = sphere.Radius.Value; - collider.Offset = Vector3InvertX(sphere.Offset); - } - else if (c.Shape.Capsule is UniGLTF.Extensions.VRMC_springBone.ColliderShapeCapsule capsule) - { - collider.ColliderType = VRM10SpringBoneColliderTypes.Capsule; - collider.Radius = capsule.Radius.Value; - collider.Offset = Vector3InvertX(capsule.Offset); - collider.Tail = Vector3InvertX(capsule.Tail); - } - else - { - throw new NotImplementedException(); + var collider = node.gameObject.AddComponent(); + colliderGroup.Colliders.Add(collider); + + if (c.Shape.Sphere is UniGLTF.Extensions.VRMC_springBone.ColliderShapeSphere sphere) + { + collider.ColliderType = VRM10SpringBoneColliderTypes.Sphere; + collider.Radius = sphere.Radius.Value; + collider.Offset = Vector3InvertX(sphere.Offset); + } + else if (c.Shape.Capsule is UniGLTF.Extensions.VRMC_springBone.ColliderShapeCapsule capsule) + { + collider.ColliderType = VRM10SpringBoneColliderTypes.Capsule; + collider.Radius = capsule.Radius.Value; + collider.Offset = Vector3InvertX(capsule.Offset); + collider.Tail = Vector3InvertX(capsule.Tail); + } + else + { + throw new NotImplementedException(); + } } } } - foreach (var gltfSpring in gltfVrmSpringBone.Springs) + if (gltfVrmSpringBone.Springs != null) { - if (gltfSpring.Joints == null || gltfSpring.Joints.Count == 0) + foreach (var gltfSpring in gltfVrmSpringBone.Springs) { - continue; - } - var spring = new VRM10ControllerSpringBone.Spring(gltfSpring.Name); - controller.SpringBone.Springs.Add(spring); - - spring.ColliderGroups = gltfSpring.ColliderGroups.Select(x => controller.SpringBone.ColliderGroups[x]).ToList(); - // joint - foreach (var gltfJoint in gltfSpring.Joints) - { - if (gltfJoint.Node.HasValue) + if (gltfSpring.Joints == null || gltfSpring.Joints.Count == 0) { - var index = gltfJoint.Node.Value; - if (index < 0 || index >= Nodes.Count) + continue; + } + var spring = new VRM10ControllerSpringBone.Spring(gltfSpring.Name); + controller.SpringBone.Springs.Add(spring); + + if (gltfSpring.ColliderGroups != null) + { + spring.ColliderGroups = gltfSpring.ColliderGroups.Select(x => controller.SpringBone.ColliderGroups[x]).ToList(); + } + // joint + foreach (var gltfJoint in gltfSpring.Joints) + { + if (gltfJoint.Node.HasValue) { - throw new IndexOutOfRangeException($"{index} > {Nodes.Count}"); + var index = gltfJoint.Node.Value; + if (index < 0 || index >= Nodes.Count) + { + throw new IndexOutOfRangeException($"{index} > {Nodes.Count}"); + } + var joint = Nodes[gltfJoint.Node.Value].gameObject.AddComponent(); + joint.m_jointRadius = gltfJoint.HitRadius.Value; + joint.m_dragForce = gltfJoint.DragForce.Value; + joint.m_gravityDir = Vector3InvertX(gltfJoint.GravityDir); + joint.m_gravityPower = gltfJoint.GravityPower.Value; + joint.m_stiffnessForce = gltfJoint.Stiffness.Value; + // joint.m_exclude = gltfJoint.Exclude.GetValueOrDefault(); + spring.Joints.Add(joint); } - var joint = Nodes[gltfJoint.Node.Value].gameObject.AddComponent(); - joint.m_jointRadius = gltfJoint.HitRadius.Value; - joint.m_dragForce = gltfJoint.DragForce.Value; - joint.m_gravityDir = Vector3InvertX(gltfJoint.GravityDir); - joint.m_gravityPower = gltfJoint.GravityPower.Value; - joint.m_stiffnessForce = gltfJoint.Stiffness.Value; - // joint.m_exclude = gltfJoint.Exclude.GetValueOrDefault(); - spring.Joints.Add(joint); } } }