diff --git a/unity/Editor/Components/MjMouseSpring.cs b/unity/Editor/Components/MjMouseSpring.cs index 7e1c24626a..7d3dc8dc1b 100644 --- a/unity/Editor/Components/MjMouseSpring.cs +++ b/unity/Editor/Components/MjMouseSpring.cs @@ -26,6 +26,7 @@ namespace Mujoco { public class MjMouseSpring : Editor { private bool _lastShiftKeyState = false; + private int _controlID = -1; private Plane _mouseDragPlane; private Vector3 _mouseDragCurrentPoint = Vector3.negativeInfinity; @@ -33,8 +34,7 @@ public class MjMouseSpring : Editor { public void OnDisable() { // If we're still the hot control at this stage, we need to release. - int uniqueID = GUIUtility.GetControlID(FocusType.Passive); - if (GUIUtility.hotControl == uniqueID) { + if (GUIUtility.hotControl == _controlID) { GUIUtility.hotControl = 0; } } @@ -86,6 +86,7 @@ public unsafe void OnSceneGUI() { // Cache the hot control to determine whether we're currently capturing mouse input. int uniqueID = GUIUtility.GetControlID(FocusType.Passive); + _controlID = uniqueID; // Mouse spring is active if the control key is held down and the user is dragging the // left mouse button, or if we're already in the process of capturing mouse input. diff --git a/unity/Editor/Importer/MjImporterWithAssets.cs b/unity/Editor/Importer/MjImporterWithAssets.cs index c724e3a0f0..93432d8808 100644 --- a/unity/Editor/Importer/MjImporterWithAssets.cs +++ b/unity/Editor/Importer/MjImporterWithAssets.cs @@ -153,7 +153,7 @@ private void ParseMesh(XmlElement parentNode) { var assetReferenceName = MjEngineTool.Sanitize(unsanitizedAssetReferenceName); var sourceFilePath = Path.Combine(_sourceMeshesDir, fileName); - if (Path.GetExtension(sourceFilePath) != ".obj" && Path.GetExtension(sourceFilePath) != ".stl") { + if (Path.GetExtension(sourceFilePath).ToLower() != ".obj" && Path.GetExtension(sourceFilePath).ToLower() != ".stl") { throw new NotImplementedException("Type of mesh file not yet supported. " + "Please convert to binary STL or OBJ. " + $"Attempted to load: {sourceFilePath}"); @@ -194,11 +194,11 @@ private void ParseMesh(XmlElement parentNode) { private void CopyMeshAndRescale( string sourceFilePath, string targetFilePath, Vector3 scale) { var originalMeshBytes = File.ReadAllBytes(sourceFilePath); - if (Path.GetExtension(sourceFilePath) == ".stl") { + if (Path.GetExtension(sourceFilePath).ToLower() == ".stl") { var mesh = StlMeshParser.ParseBinary(originalMeshBytes, scale); var rescaledMeshBytes = StlMeshParser.SerializeBinary(mesh); File.WriteAllBytes(targetFilePath, rescaledMeshBytes); - } else if (Path.GetExtension(sourceFilePath) == ".obj") { + } else if (Path.GetExtension(sourceFilePath).ToLower() == ".obj") { ObjMeshImportUtility.CopyAndScaleOBJFile(sourceFilePath, targetFilePath, scale); } else { throw new NotImplementedException($"Extension {Path.GetExtension(sourceFilePath)} " + @@ -227,7 +227,7 @@ private void ParseMaterial(XmlElement parentNode) { AssetDatabase.GUIDToAssetPath( AssetDatabase.FindAssets(_semiTransparentMaterialName)[0])) as Material); } else { - material = new Material(Shader.Find("Standard")); + material = new Material(MjcfImporter.GetLitShader()); } material.SetColor("_Color", albedo); material.SetFloat("_Metallic", reflectance); @@ -284,7 +284,7 @@ private void ResolveOrCreateMaterial(MeshRenderer renderer, XmlElement parentNod AssetDatabase.GUIDToAssetPath( AssetDatabase.FindAssets(_semiTransparentMaterialName)[0])) as Material); } else { - material = new Material(Shader.Find("Standard")); + material = new Material(MjcfImporter.GetLitShader()); } material.color = new Color(rgba[0], rgba[1], rgba[2], rgba[3]); // We use the geom's name, guaranteed to be unique, as the asset name. diff --git a/unity/Runtime/Importer/MjcfImporter.cs b/unity/Runtime/Importer/MjcfImporter.cs index 7218100705..898504c232 100644 --- a/unity/Runtime/Importer/MjcfImporter.cs +++ b/unity/Runtime/Importer/MjcfImporter.cs @@ -17,6 +17,7 @@ using System.Linq; using System.Xml; using UnityEngine; +using UnityEngine.Rendering; namespace Mujoco { // API for importing Mujoco XML files into Unity scenes. @@ -28,7 +29,7 @@ public class MjcfImporter { public static Material DefaultMujocoMaterial { get { if (_DefaultMujocoMaterial == null) { - _DefaultMujocoMaterial = new Material(Shader.Find("Standard")); + _DefaultMujocoMaterial = new Material(GetLitShader()); } return _DefaultMujocoMaterial; @@ -446,5 +447,24 @@ private GameObject CreateGameObjectWithCamera( camera.nearClipPlane = 0.01f; // MuJoCo default, TODO(etom): get from visual/map/znear return gameObject; } + + public static Shader GetLitShader() { + // Built-in pipeline is deprecated, we'll default to URP + string shaderName = "Universal Render Pipeline/Lit"; + + if (GraphicsSettings.currentRenderPipeline != null) { + string pipelineType = GraphicsSettings.currentRenderPipeline.GetType().ToString(); + + if (pipelineType.Contains("Universal")) { + shaderName = + "Universal Render Pipeline/Lit"; + } else if (pipelineType.Contains("HighDefinition")) { + shaderName = "HDRP/Lit"; + } + } + Shader shader = Shader.Find(shaderName); + return shader; + } } + } diff --git a/unity/Runtime/Resources/mujoco_semitransparent_template.mat b/unity/Runtime/Resources/mujoco_semitransparent_template.mat index cc5cb0def8..34c6cc8e2a 100644 --- a/unity/Runtime/Resources/mujoco_semitransparent_template.mat +++ b/unity/Runtime/Resources/mujoco_semitransparent_template.mat @@ -2,23 +2,38 @@ %TAG !u! tag:unity3d.com,2011: --- !u!21 &2100000 Material: - serializedVersion: 6 + serializedVersion: 8 m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_Name: mujoco_semitransparent_template - m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} - m_ShaderKeywords: + m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3} + m_Parent: {fileID: 0} + m_ModifiedSerializedProperties: 0 + m_ValidKeywords: + - _ALPHAPREMULTIPLY_ON + - _SPECULAR_SETUP + - _SURFACE_TYPE_TRANSPARENT + m_InvalidKeywords: [] m_LightmapFlags: 4 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 - m_CustomRenderQueue: -1 - stringTagMap: {} - disabledShaderPasses: [] + m_CustomRenderQueue: 3000 + stringTagMap: + RenderType: Transparent + disabledShaderPasses: + - MOTIONVECTORS + - DepthOnly + - SHADOWCASTER + m_LockedProperties: m_SavedProperties: serializedVersion: 3 m_TexEnvs: + - _BaseMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} - _BumpMap: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} @@ -55,11 +70,40 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + - _SpecGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_Lightmaps: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_LightmapsInd: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_ShadowMasks: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Ints: [] m_Floats: + - _AddPrecomputedVelocity: 0 + - _AlphaClip: 0 + - _AlphaToMask: 0 + - _Blend: 0 + - _BlendModePreserveSpecular: 1 + - _BlendOp: 0 - _BumpScale: 1 + - _ClearCoatMask: 0 + - _ClearCoatSmoothness: 0 + - _Cull: 2 - _Cutoff: 0.5 + - _DetailAlbedoMapScale: 1 - _DetailNormalMapScale: 1 - - _DstBlend: 0 + - _DstBlend: 10 + - _DstBlendAlpha: 10 + - _EnvironmentReflections: 1 - _GlossMapScale: 1 - _Glossiness: 0.5 - _GlossyReflections: 1 @@ -67,11 +111,36 @@ Material: - _Mode: 0 - _OcclusionStrength: 1 - _Parallax: 0.02 + - _QueueOffset: 0 + - _ReceiveShadows: 1 + - _SampleGI: 0 + - _Smoothness: 0.5 - _SmoothnessTextureChannel: 0 - _SpecularHighlights: 1 - _SrcBlend: 1 + - _SrcBlendAlpha: 1 + - _Surface: 1 - _UVSec: 0 - - _ZWrite: 1 + - _WorkflowMode: 0 + - _XRMotionVectorsPass: 1 + - _ZWrite: 0 m_Colors: + - _BaseColor: {r: 1, g: 1, b: 1, a: 1} - _Color: {r: 1, g: 1, b: 1, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + - _SpecColor: {r: 0.2, g: 0.2, b: 0.2, a: 1} + m_BuildTextureStacks: [] + m_AllowLocking: 1 +--- !u!114 &3406183217315982671 +MonoBehaviour: + m_ObjectHideFlags: 11 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3} + m_Name: + m_EditorClassIdentifier: Unity.RenderPipelines.Universal.Editor::UnityEditor.Rendering.Universal.AssetVersion + version: 10 diff --git a/unity/Runtime/Resources/mujoco_semitransparent_template.mat.meta b/unity/Runtime/Resources/mujoco_semitransparent_template.mat.meta index 16ec73d34f..00cae99c39 100644 --- a/unity/Runtime/Resources/mujoco_semitransparent_template.mat.meta +++ b/unity/Runtime/Resources/mujoco_semitransparent_template.mat.meta @@ -3,6 +3,6 @@ guid: 4daefe8934610e978b13f883bfb904cf NativeFormatImporter: externalObjects: {} mainObjectFileID: 2100000 - userData: - assetBundleName: - assetBundleVariant: + userData: + assetBundleName: + assetBundleVariant: