Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions unity/Editor/Components/MjMouseSpring.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ namespace Mujoco {
public class MjMouseSpring : Editor {
private bool _lastShiftKeyState = false;

private int _controlID = -1;
private Plane _mouseDragPlane;
private Vector3 _mouseDragCurrentPoint = Vector3.negativeInfinity;

private Color _translucentRed = new Color(1, 0, 0, 0.1f);

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;
}
}
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions unity/Editor/Importer/MjImporterWithAssets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
Expand Down Expand Up @@ -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)} " +
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down
22 changes: 21 additions & 1 deletion unity/Runtime/Importer/MjcfImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}

}
85 changes: 77 additions & 8 deletions unity/Runtime/Resources/mujoco_semitransparent_template.mat
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -55,23 +70,77 @@ 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
- _Metallic: 0
- _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

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

Loading