diff --git a/Assets/Resources/Meshes.meta b/Assets/Resources/Meshes.meta deleted file mode 100644 index 4c9af935..00000000 --- a/Assets/Resources/Meshes.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 41ca95647bc227f1ea34d0346b3c5655 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Resources/Meshes/.gitkeep b/Assets/Resources/Meshes/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Assets/Resources/RenderPipelines/UniversalRenderPipelineAsset.asset b/Assets/Resources/RenderPipelines/UniversalRenderPipelineAsset.asset index 6f3329e0..1e57b244 100644 --- a/Assets/Resources/RenderPipelines/UniversalRenderPipelineAsset.asset +++ b/Assets/Resources/RenderPipelines/UniversalRenderPipelineAsset.asset @@ -26,7 +26,7 @@ MonoBehaviour: m_SupportsTerrainHoles: 0 m_SupportsHDR: 1 m_HDRColorBufferPrecision: 0 - m_MSAA: 4 + m_MSAA: 1 m_RenderScale: 1 m_UpscalingFilter: 0 m_FsrOverrideSharpness: 0 @@ -84,7 +84,7 @@ MonoBehaviour: blueNoise64LTex: {fileID: 2800000, guid: e3d24661c1e055f45a7560c033dbb837, type: 3} bayerMatrixTex: {fileID: 2800000, guid: f9ee4ed84c1d10c49aabb9b210b0fc44, type: 3} m_PrefilteringModeMainLightShadows: 3 - m_PrefilteringModeAdditionalLight: 0 + m_PrefilteringModeAdditionalLight: 4 m_PrefilteringModeAdditionalLightShadows: 2 m_PrefilterXRKeywords: 1 m_PrefilteringModeForwardPlus: 1 diff --git a/Assets/Resources/Shader/UnlitVideoTexture.shader b/Assets/Resources/Shader/UnlitVideoTexture.shader new file mode 100644 index 00000000..7b4f50f0 --- /dev/null +++ b/Assets/Resources/Shader/UnlitVideoTexture.shader @@ -0,0 +1,147 @@ +// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' + +Shader "Custom/Unlit/VideoTexture" +{ + Properties + { + _MainTex ("Texture", 2D) = "white" {} + } + SubShader + { + Tags { "RenderType"="Opaque" } + LOD 100 + + Pass + { + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + // make fog work + #pragma multi_compile_fog + + #include "UnityCG.cginc" + + struct appdata + { + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + }; + + struct v2f + { + float2 uv : TEXCOORD0; + UNITY_FOG_COORDS(1) + float4 vertex : SV_POSITION; + }; + + sampler2D _MainTex; + float4 _MainTex_ST; + + v2f vert (appdata v) + { + v2f o; + + o.vertex = UnityObjectToClipPos(v.vertex); + + // rotating UV + const float Deg2Rad = (UNITY_PI * 2.0) / 360.0; + const float Rotation = 90.0; + + float rotationRadians = Rotation * Deg2Rad; // convert degrees to radians + float s = sin(rotationRadians); // sin and cos take radians, not degrees + float c = cos(rotationRadians); + + float2x2 rotationMatrix = float2x2( c, -s, s, c); // construct simple rotation matrix + v.uv -= 0.5; // offset UV so we rotate around 0.5 and not 0.0 + v.uv = mul(rotationMatrix, v.uv); // apply rotation matrix + v.uv += 0.5; // offset UV again so UVs are in the correct location + + o.uv = TRANSFORM_TEX(v.uv, _MainTex); + UNITY_TRANSFER_FOG(o,o.vertex); + return o; + } + + fixed4 frag (v2f i) : SV_Target + { + // sample the texture + fixed4 col = tex2D(_MainTex, i.uv); + // apply fog + UNITY_APPLY_FOG(i.fogCoord, col); + return col; + } + ENDCG + } + } +} + + +// Shader "Example/URPUnlitShaderTexture" +// { +// // The _BaseMap variable is visible in the Material's Inspector, as a field +// // called Base Map. +// Properties +// { +// _BaseMap("Base Map", 2D) = "white" +// } + +// SubShader +// { +// Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalRenderPipeline" } + +// Pass +// { +// HLSLPROGRAM +// #pragma vertex vert +// #pragma fragment frag + +// #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + +// struct Attributes +// { +// float4 positionOS : POSITION; +// // The uv variable contains the UV coordinate on the texture for the +// // given vertex. +// float2 uv : TEXCOORD0; +// }; + +// struct Varyings +// { +// float4 positionHCS : SV_POSITION; +// // The uv variable contains the UV coordinate on the texture for the +// // given vertex. +// float2 uv : TEXCOORD0; +// }; + +// // This macro declares _BaseMap as a Texture2D object. +// TEXTURE2D(_BaseMap); +// // This macro declares the sampler for the _BaseMap texture. +// SAMPLER(sampler_BaseMap); + +// CBUFFER_START(UnityPerMaterial) +// // The following line declares the _BaseMap_ST variable, so that you +// // can use the _BaseMap variable in the fragment shader. The _ST +// // suffix is necessary for the tiling and offset function to work. +// float4 _BaseMap_ST; +// CBUFFER_END + +// Varyings vert(Attributes IN) +// { +// Varyings OUT; +// OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz); +// // The TRANSFORM_TEX macro performs the tiling and offset +// // transformation. +// OUT.uv = TRANSFORM_TEX(IN.uv, _BaseMap); +// return OUT; +// } + +// half4 frag(Varyings IN) : SV_Target +// { +// // The SAMPLE_TEXTURE2D marco samples the texture with the given +// // sampler. +// half4 color = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, IN.uv); +// return color; +// } +// ENDHLSL +// } +// } +// } \ No newline at end of file diff --git a/Assets/Resources/Shader/UnlitVideoTexture.shader.meta b/Assets/Resources/Shader/UnlitVideoTexture.shader.meta new file mode 100644 index 00000000..c16c020f --- /dev/null +++ b/Assets/Resources/Shader/UnlitVideoTexture.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: deae5ca476ee55d65b15a5f91a73287d +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/CLOiSimPlugins/ActorControlPlugin.cs b/Assets/Scripts/CLOiSimPlugins/ActorControlPlugin.cs index 85cc1711..bbc079a8 100644 --- a/Assets/Scripts/CLOiSimPlugins/ActorControlPlugin.cs +++ b/Assets/Scripts/CLOiSimPlugins/ActorControlPlugin.cs @@ -21,7 +21,8 @@ public class ActorControlPlugin : CLOiSimPlugin protected override void OnAwake() { type = ICLOiSimPlugin.Type.ACTOR; - partsName = "ActorControlPlugin"; + _modelName = "World"; + _partsName = this.GetType().Name; UpdateActorList(); } diff --git a/Assets/Scripts/CLOiSimPlugins/ActorPlugin.cs b/Assets/Scripts/CLOiSimPlugins/ActorPlugin.cs index ad5ba54b..020e61e3 100644 --- a/Assets/Scripts/CLOiSimPlugins/ActorPlugin.cs +++ b/Assets/Scripts/CLOiSimPlugins/ActorPlugin.cs @@ -12,7 +12,8 @@ public class ActorPlugin : CLOiSimPlugin protected override void OnAwake() { type = ICLOiSimPlugin.Type.ACTOR; - partsName = "actorplugin"; + _modelName = "World"; + _partsName = this.GetType().Name; } protected override void OnStart() diff --git a/Assets/Scripts/CLOiSimPlugins/CameraPlugin.cs b/Assets/Scripts/CLOiSimPlugins/CameraPlugin.cs index b7f72dfe..adc63681 100644 --- a/Assets/Scripts/CLOiSimPlugins/CameraPlugin.cs +++ b/Assets/Scripts/CLOiSimPlugins/CameraPlugin.cs @@ -29,9 +29,9 @@ protected override void OnAwake() } if (!string.IsNullOrEmpty(deviceName)) + { attachedDevices.Add(deviceName, _cam); - - partsName = DeviceHelper.GetPartName(gameObject); + } } protected override void OnStart() diff --git a/Assets/Scripts/CLOiSimPlugins/ElevatorSystem.cs b/Assets/Scripts/CLOiSimPlugins/ElevatorSystem.cs index f1938f81..3cd676f2 100644 --- a/Assets/Scripts/CLOiSimPlugins/ElevatorSystem.cs +++ b/Assets/Scripts/CLOiSimPlugins/ElevatorSystem.cs @@ -53,7 +53,8 @@ public ElevatorTask(in string index = "") protected override void OnAwake() { type = ICLOiSimPlugin.Type.ELEVATOR; - partsName = "elevator_system"; + _modelName = "World"; + _partsName = this.GetType().Name; } protected override void OnStart() diff --git a/Assets/Scripts/CLOiSimPlugins/GpsPlugin.cs b/Assets/Scripts/CLOiSimPlugins/GpsPlugin.cs index 7f6cd728..d26f97c5 100644 --- a/Assets/Scripts/CLOiSimPlugins/GpsPlugin.cs +++ b/Assets/Scripts/CLOiSimPlugins/GpsPlugin.cs @@ -13,9 +13,9 @@ public class GpsPlugin : CLOiSimPlugin protected override void OnAwake() { type = ICLOiSimPlugin.Type.GPS; + gps = gameObject.GetComponent(); attachedDevices.Add("GPS", gps); - partsName = DeviceHelper.GetPartName(gameObject); } protected override void OnStart() diff --git a/Assets/Scripts/CLOiSimPlugins/GroundTruthPlugin.cs b/Assets/Scripts/CLOiSimPlugins/GroundTruthPlugin.cs index f242ab46..e60064be 100644 --- a/Assets/Scripts/CLOiSimPlugins/GroundTruthPlugin.cs +++ b/Assets/Scripts/CLOiSimPlugins/GroundTruthPlugin.cs @@ -105,9 +105,8 @@ private UE.GameObject GetTrackingObject(in string modelName) protected override void OnAwake() { type = ICLOiSimPlugin.Type.GROUNDTRUTH; - - modelName = "GroundTruth"; - partsName = "tracking"; + _modelName = "World"; + _partsName = this.GetType().Name; var worldRoot = Main.WorldRoot; foreach (var model in worldRoot.GetComponentsInChildren()) diff --git a/Assets/Scripts/CLOiSimPlugins/ImuPlugin.cs b/Assets/Scripts/CLOiSimPlugins/ImuPlugin.cs index e9c0b14b..84ad8bfc 100644 --- a/Assets/Scripts/CLOiSimPlugins/ImuPlugin.cs +++ b/Assets/Scripts/CLOiSimPlugins/ImuPlugin.cs @@ -13,9 +13,9 @@ public class ImuPlugin : CLOiSimPlugin protected override void OnAwake() { type = ICLOiSimPlugin.Type.IMU; + imu = gameObject.GetComponent(); attachedDevices.Add("IMU", imu); - partsName = DeviceHelper.GetPartName(gameObject); } protected override void OnStart() diff --git a/Assets/Scripts/CLOiSimPlugins/JointControlPlugin.cs b/Assets/Scripts/CLOiSimPlugins/JointControlPlugin.cs index e42c24f0..fea6b4a2 100644 --- a/Assets/Scripts/CLOiSimPlugins/JointControlPlugin.cs +++ b/Assets/Scripts/CLOiSimPlugins/JointControlPlugin.cs @@ -18,6 +18,7 @@ public class JointControlPlugin : CLOiSimPlugin protected override void OnAwake() { type = ICLOiSimPlugin.Type.JOINTCONTROL; + jointState = gameObject.AddComponent(); jointCommand = gameObject.AddComponent(); jointCommand.SetJointState(jointState); diff --git a/Assets/Scripts/CLOiSimPlugins/LaserPlugin.cs b/Assets/Scripts/CLOiSimPlugins/LaserPlugin.cs index 87557cb6..bb4c85fc 100644 --- a/Assets/Scripts/CLOiSimPlugins/LaserPlugin.cs +++ b/Assets/Scripts/CLOiSimPlugins/LaserPlugin.cs @@ -14,7 +14,6 @@ public class LaserPlugin : CLOiSimPlugin protected override void OnAwake() { type = ICLOiSimPlugin.Type.LASER; - partsName = DeviceHelper.GetPartName(gameObject); lidar = GetComponent(); attachedDevices.Add("LIDAR", lidar); diff --git a/Assets/Scripts/CLOiSimPlugins/MicomPlugin.cs b/Assets/Scripts/CLOiSimPlugins/MicomPlugin.cs index 06bd8788..d695e3bc 100644 --- a/Assets/Scripts/CLOiSimPlugins/MicomPlugin.cs +++ b/Assets/Scripts/CLOiSimPlugins/MicomPlugin.cs @@ -10,6 +10,7 @@ using System; using Any = cloisim.msgs.Any; using UnityEngine; +using UnityEngine.Video; public class MicomPlugin : CLOiSimPlugin { @@ -20,9 +21,12 @@ public class MicomPlugin : CLOiSimPlugin private SDF.Helper.Link[] _linkHelperInChildren = null; private StringBuilder _log = new StringBuilder(); + private List _displaySourceUris = new List(); + protected override void OnAwake() { type = ICLOiSimPlugin.Type.MICOM; + _partsName = (GetPluginParameters() == null || string.IsNullOrEmpty(GetPluginParameters().Name)) ? "Micom" : GetPluginParameters().Name; _micomSensor = gameObject.AddComponent(); _micomCommand = gameObject.AddComponent(); @@ -65,7 +69,6 @@ protected override void OnStart() Debug.Log(_log.ToString()); } - protected override void OnReset() { _motorControl?.Reset(); @@ -131,6 +134,64 @@ private void SetupMicom() { _micomSensor.SetIMU(targetImuSensorName); } + + if (GetPluginParameters().IsValidNode("display")) + { + SetDisplay(); + } + } + + private void SetDisplay() + { + const float meshScalingFactor = 1000f; + var targetVisual = GetPluginParameters().GetValue("display/target/visual", string.Empty); + + if (string.IsNullOrEmpty(targetVisual)) + { + _log.AppendLine("Failed to set display - Empty target visual for display"); + return; + } + + if (GetPluginParameters().GetValues("display/source/uri", out _displaySourceUris) == false) + { + _log.AppendLine("Failed to set display - Empty display source uri"); + return; + } + + var defaultSourceUri = GetPluginParameters().GetValue("display/source/uri[@default='true']", _displaySourceUris[0]); + + var visualHelpers = GetComponentsInChildren(); + foreach (var visualHelper in visualHelpers) + { + if (visualHelper.name.Equals(targetVisual)) + { + var meshFilter = visualHelper.GetComponentInChildren(); + var mesh = meshFilter.sharedMesh; + var displaySize = mesh.bounds.size; + var videoWidth = (int)(displaySize.x * meshScalingFactor); + var videoHeight = (int)(displaySize.z * meshScalingFactor); + + var renderTexture = new RenderTexture(videoWidth, videoHeight, 0); + renderTexture.name = "VideoTexture"; + + var meshRenderer = visualHelper.GetComponentInChildren(); + var shader = Shader.Find("Custom/Unlit/VideoTexture"); + meshRenderer.material = new Material(shader); + meshRenderer.sharedMaterial.SetTexture("_MainTex", renderTexture); + + var videoPlayer = visualHelper.gameObject.AddComponent(); + videoPlayer.audioOutputMode = VideoAudioOutputMode.None; + videoPlayer.isLooping = true; + videoPlayer.source = VideoSource.Url; + videoPlayer.playOnAwake = true; + videoPlayer.waitForFirstFrame = true; + videoPlayer.url = defaultSourceUri; + videoPlayer.renderMode = VideoRenderMode.RenderTexture; + videoPlayer.targetTexture = renderTexture; + videoPlayer.aspectRatio = VideoAspectRatio.Stretch; + break; + } + } } private void SetSelfBalancedWheel(in string parameterPrefix) @@ -194,6 +255,12 @@ private void SetSelfBalancedWheel(in string parameterPrefix) (_motorControl as SelfBalancedDrive).SetBodyJoint(bodyJoint); } + if (GetPluginParameters().IsValidNode($"{parameterPrefix}/body/rotation/hip_adjust")) + { + var adjust = GetPluginParameters().GetValue($"{parameterPrefix}/body/rotation/hip_adjust", 1.88); + (_motorControl as SelfBalancedDrive).AdjustBodyRotation = adjust; + } + if (GetPluginParameters().IsValidNode($"{parameterPrefix}/smc")) { if (GetPluginParameters().IsValidNode($"{parameterPrefix}/smc/param")) @@ -370,7 +437,7 @@ private void SetBattery() private void LoadStaticTF() { - _log.AppendLine("Loaded Static TF Info : " + modelName); + _log.AppendLine("Loaded Static TF Info : " + _modelName); if (GetPluginParameters().GetValues("ros2/static_transforms/link", out var staticLinks)) { @@ -398,7 +465,7 @@ private void LoadStaticTF() private void LoadTF() { - _log.AppendLine("Loaded TF Info : " + modelName); + _log.AppendLine("Loaded TF Info : " + _modelName); if (GetPluginParameters().GetValues("ros2/transforms/link", out var links)) { diff --git a/Assets/Scripts/CLOiSimPlugins/Modules/Base/CLOiSimMultiPlugin.cs b/Assets/Scripts/CLOiSimPlugins/Modules/Base/CLOiSimMultiPlugin.cs index dff609b6..23dbbc72 100644 --- a/Assets/Scripts/CLOiSimPlugins/Modules/Base/CLOiSimMultiPlugin.cs +++ b/Assets/Scripts/CLOiSimPlugins/Modules/Base/CLOiSimMultiPlugin.cs @@ -8,10 +8,10 @@ public abstract class CLOiSimMultiPlugin : CLOiSimPlugin { - private Dictionary CLOiSimPlugins = new Dictionary(); + private Dictionary _CLOiSimPlugins = new Dictionary(); - public void AddCLOiSimPlugin(in string deviceName, in CLOiSimPlugin CLOiSimPlugin) + public void AddPlugin(in string deviceName, in CLOiSimPlugin CLOiSimPlugin) { - CLOiSimPlugins.Add(deviceName, CLOiSimPlugin); + _CLOiSimPlugins.Add(deviceName, CLOiSimPlugin); } } \ No newline at end of file diff --git a/Assets/Scripts/CLOiSimPlugins/Modules/Base/CLOiSimPlugin.CommonMethod.cs b/Assets/Scripts/CLOiSimPlugins/Modules/Base/CLOiSimPlugin.CommonMethod.cs index b7594a45..cfa1b987 100644 --- a/Assets/Scripts/CLOiSimPlugins/Modules/Base/CLOiSimPlugin.CommonMethod.cs +++ b/Assets/Scripts/CLOiSimPlugins/Modules/Base/CLOiSimPlugin.CommonMethod.cs @@ -158,33 +158,12 @@ protected static void SetEmptyResponse(ref DeviceMessage msRos2Info) private void SetCustomHandleRequestMessage() { - thread.HandleRequestTypeValue = delegate (in string requestType, in Any requestValue, ref DeviceMessage response) + _thread.HandleRequestTypeValue = delegate (in string requestType, in Any requestValue, ref DeviceMessage response) { switch (requestType) { case "request_ros2": - if (GetPluginParameters().IsValidNode("ros2")) - { - var topic_name = GetPluginParameters().GetValue("ros2/topic_name[@add_parts_name_prefix='true']"); - if (string.IsNullOrEmpty(topic_name)) - { - topic_name = GetPluginParameters().GetValue("ros2/topic_name", partsName); - topic_name = topic_name.Replace("{parts_name}", partsName); - } - else - { - topic_name = partsName + "/" + topic_name; - } - - GetPluginParameters().GetValues("ros2/frame_id", out var frameIdList); - - for (var i = 0; i < frameIdList.Count; i++) - { - frameIdList[i] = frameIdList[i].Replace("{parts_name}", partsName); - } - - SetROS2CommonInfoResponse(ref response, topic_name, frameIdList); - } + SetRequestRos2Response(ref response); break; case "request_static_transforms": @@ -197,12 +176,38 @@ private void SetCustomHandleRequestMessage() } }; - thread.HandleRequestTypeChildren = delegate (in string requestType, in List requestChildren, ref DeviceMessage response) + _thread.HandleRequestTypeChildren = delegate (in string requestType, in List requestChildren, ref DeviceMessage response) { HandleCustomRequestMessage(requestType, requestChildren, ref response); }; } + protected virtual void SetRequestRos2Response(ref DeviceMessage msRos2Info) + { + if (GetPluginParameters().IsValidNode("ros2")) + { + var topic_name = GetPluginParameters().GetValue("ros2/topic_name[@add_parts_name_prefix='true']"); + if (string.IsNullOrEmpty(topic_name)) + { + topic_name = GetPluginParameters().GetValue("ros2/topic_name", _partsName); + topic_name = topic_name.Replace("{parts_name}", _partsName); + } + else + { + topic_name = _partsName + "/" + topic_name; + } + + GetPluginParameters().GetValues("ros2/frame_id", out var frameIdList); + + for (var i = 0; i < frameIdList.Count; i++) + { + frameIdList[i] = frameIdList[i].Replace("{parts_name}", _partsName); + } + + SetROS2CommonInfoResponse(ref msRos2Info, topic_name, frameIdList); + } + } + private void SetStaticTransformsResponse(ref DeviceMessage msRos2Info) { if (msRos2Info == null) diff --git a/Assets/Scripts/CLOiSimPlugins/Modules/Base/CLOiSimPlugin.Thread.cs b/Assets/Scripts/CLOiSimPlugins/Modules/Base/CLOiSimPlugin.Thread.cs index 36729854..20001cc9 100644 --- a/Assets/Scripts/CLOiSimPlugins/Modules/Base/CLOiSimPlugin.Thread.cs +++ b/Assets/Scripts/CLOiSimPlugins/Modules/Base/CLOiSimPlugin.Thread.cs @@ -10,12 +10,12 @@ public abstract partial class CLOiSimPlugin : MonoBehaviour, ICLOiSimPlugin { - private CLOiSimPluginThread thread = new CLOiSimPluginThread(); - protected CLOiSimPluginThread PluginThread => thread; + private CLOiSimPluginThread _thread = new CLOiSimPluginThread(); + protected CLOiSimPluginThread PluginThread => _thread; protected bool AddThread(in ushort targetPortForThread, in ParameterizedThreadStart function, in System.Object paramObject = null) { - return thread.Add(targetPortForThread, function, paramObject); + return _thread.Add(targetPortForThread, function, paramObject); } protected void SenderThread(System.Object threadObject) @@ -24,7 +24,7 @@ protected void SenderThread(System.Object threadObject) var publisher = GetTransport().Get(paramObject.targetPort); var deviceParam = paramObject.param as Device; - thread.Sender(publisher, deviceParam); + _thread.Sender(publisher, deviceParam); } protected void ReceiverThread(System.Object threadObject) @@ -33,7 +33,7 @@ protected void ReceiverThread(System.Object threadObject) var subscriber = GetTransport().Get(paramObject.targetPort); var deviceParam = paramObject.param as Device; - thread.Receiver(subscriber, deviceParam); + _thread.Receiver(subscriber, deviceParam); } protected void ServiceThread(System.Object threadObject) @@ -41,6 +41,6 @@ protected void ServiceThread(System.Object threadObject) var paramObject = threadObject as CLOiSimPluginThread.ParamObject; var responsor = GetTransport().Get(paramObject.targetPort); - thread.Service(responsor); + _thread.Service(responsor); } } \ No newline at end of file diff --git a/Assets/Scripts/CLOiSimPlugins/Modules/Base/CLOiSimPlugin.Transport.cs b/Assets/Scripts/CLOiSimPlugins/Modules/Base/CLOiSimPlugin.Transport.cs index ca8689cc..f9d9e59a 100644 --- a/Assets/Scripts/CLOiSimPlugins/Modules/Base/CLOiSimPlugin.Transport.cs +++ b/Assets/Scripts/CLOiSimPlugins/Modules/Base/CLOiSimPlugin.Transport.cs @@ -9,24 +9,25 @@ public abstract partial class CLOiSimPlugin : MonoBehaviour, ICLOiSimPlugin { - private Transporter transport = new Transporter(); + private Transporter _transport = new Transporter(); - private string subPartsName = string.Empty; + [SerializeField] + private string _subPartsName = string.Empty; public string SubPartsName { - get => this.subPartsName; - set => this.subPartsName = value; + get => this._subPartsName; + set => this._subPartsName = value; } public Transporter GetTransport() { - return transport; + return _transport; } private bool PrepareDevice(in string subPartsAndKey, out ushort port, out ulong hash) { - if (BridgeManager.AllocateDevice(type.ToString(), modelName, partsName, subPartsAndKey, out var hashKey, out port)) + if (BridgeManager.AllocateDevice(type.ToString(), _modelName, _partsName, subPartsAndKey, out var hashKey, out port)) { allocatedDeviceHashKeys.Add(hashKey); allocatedDevicePorts.Add(port); @@ -36,7 +37,7 @@ private bool PrepareDevice(in string subPartsAndKey, out ushort port, out ulong return true; } - Debug.LogError("Port for device is not allocated!!!!!!!! - " + hashKey); + Debug.LogError($"Port for device is not allocated !!! {hashKey}"); hash = 0; return false; } @@ -49,52 +50,52 @@ protected static bool DeregisterDevice(in List allocatedPorts, in List _modelName; + set => _modelName = value; + } + + public string PartsName + { + get => _partsName; + set => _partsName = value; + } protected List staticTfList = new List(); private Pose pluginPose = Pose.identity; - private SDF.Plugin _pluginParameters; + private SDF.Plugin _pluginParameters = null; private List allocatedDevicePorts = new List(); private List allocatedDeviceHashKeys = new List(); @@ -49,8 +64,8 @@ protected virtual void OnPluginLoad() { } protected void OnDestroy() { - thread.Dispose(); - transport.Dispose(); + _thread.Dispose(); + _transport.Dispose(); DeregisterDevice(allocatedDevicePorts, allocatedDeviceHashKeys); // Debug.Log($"({type.ToString()}){name}, CLOiSimPlugin destroyed."); @@ -95,19 +110,21 @@ void Start() { StorePose(); - if (string.IsNullOrEmpty(modelName)) + if (string.IsNullOrEmpty(_modelName)) { - modelName = DeviceHelper.GetModelName(gameObject); + _modelName = DeviceHelper.GetModelName(gameObject); } - if (string.IsNullOrEmpty(partsName)) + if (string.IsNullOrEmpty(_partsName)) { - partsName = _pluginParameters.Name; + _partsName = DeviceHelper.GetPartsName(gameObject); } + // Debug.LogWarning($"modelName={modelName} partsName={partsName} pluginName={pluginName}"); + OnStart(); - thread.Start(); + _thread.Start(); } public void Reset() diff --git a/Assets/Scripts/CLOiSimPlugins/Modules/Base/CLOiSimPluginThread.cs b/Assets/Scripts/CLOiSimPlugins/Modules/Base/CLOiSimPluginThread.cs index a921241a..d8685e9e 100644 --- a/Assets/Scripts/CLOiSimPlugins/Modules/Base/CLOiSimPluginThread.cs +++ b/Assets/Scripts/CLOiSimPlugins/Modules/Base/CLOiSimPluginThread.cs @@ -26,10 +26,10 @@ public ParamObject(in ushort targetPort, in System.Object parameter) } } - private List<(Thread, ParamObject)> threadList = new List<(Thread, ParamObject)>(); + private List<(Thread, ParamObject)> _threadList = new List<(Thread, ParamObject)>(); - private bool runningThread = true; - public bool IsRunning => runningThread; + private bool _runningThread = true; + public bool IsRunning => _runningThread; public delegate void RefAction(in T1 arg1, in T2 arg2, ref T3 arg3); public delegate void RefAction(in T1 arg1, ref T2 arg3); @@ -56,7 +56,7 @@ public bool Add(in ushort targetPortForThread, in ParameterizedThreadStart funct var thread = new Thread(function); var threadObject = new ParamObject(targetPortForThread, paramObject); // thread.Priority = System.Threading.ThreadPriority.AboveNormal; - threadList.Add((thread, threadObject)); + _threadList.Add((thread, threadObject)); return true; } @@ -65,9 +65,9 @@ public bool Add(in ushort targetPortForThread, in ParameterizedThreadStart funct public void Start() { - runningThread = true; + _runningThread = true; - foreach (var threadTuple in threadList) + foreach (var threadTuple in _threadList) { var thread = threadTuple.Item1; if (thread != null && !thread.IsAlive) @@ -80,9 +80,9 @@ public void Start() public void Stop() { - runningThread = false; + _runningThread = false; - foreach (var threadTuple in threadList) + foreach (var threadTuple in _threadList) { var thread = threadTuple.Item1; if (thread != null) @@ -94,7 +94,7 @@ public void Stop() } } } - threadList.Clear(); + _threadList.Clear(); } public void Sender(Publisher publisher, Device device) diff --git a/Assets/Scripts/CLOiSimPlugins/MowingPlugin.cs b/Assets/Scripts/CLOiSimPlugins/MowingPlugin.cs index 3ef7a05b..6d3c0fe0 100644 --- a/Assets/Scripts/CLOiSimPlugins/MowingPlugin.cs +++ b/Assets/Scripts/CLOiSimPlugins/MowingPlugin.cs @@ -175,9 +175,8 @@ public Vector3 GetGrassOffset() protected override void OnAwake() { type = ICLOiSimPlugin.Type.NONE; - - modelName = "Mowing"; - partsName = "_"; + _modelName = "World"; + _partsName = this.GetType().Name; var geomGrassShader = Shader.Find("Custom/GeometryGrass"); _grass = new Grass(geomGrassShader); diff --git a/Assets/Scripts/CLOiSimPlugins/MultiCameraPlugin.cs b/Assets/Scripts/CLOiSimPlugins/MultiCameraPlugin.cs index 5753988a..f8b5d93b 100644 --- a/Assets/Scripts/CLOiSimPlugins/MultiCameraPlugin.cs +++ b/Assets/Scripts/CLOiSimPlugins/MultiCameraPlugin.cs @@ -13,10 +13,8 @@ public class MultiCameraPlugin : CLOiSimPlugin protected override void OnAwake() { type = ICLOiSimPlugin.Type.MULTICAMERA; - partsName = DeviceHelper.GetPartName(gameObject); multiCam = gameObject.GetComponent(); - attachedDevices.Add("MultiCamera", multiCam); } diff --git a/Assets/Scripts/CLOiSimPlugins/ParticleSystemPlugin.cs b/Assets/Scripts/CLOiSimPlugins/ParticleSystemPlugin.cs index 00117c7d..79760d0f 100644 --- a/Assets/Scripts/CLOiSimPlugins/ParticleSystemPlugin.cs +++ b/Assets/Scripts/CLOiSimPlugins/ParticleSystemPlugin.cs @@ -13,19 +13,14 @@ [RequireComponent(typeof(ParticleSystem))] public class ParticleSystemPlugin : CLOiSimPlugin { - // private GameObject _mowingList = null; - // private Transform _targetPlaneTranform = null; private ParticleSystem _particleSystem = null; private ParticleSystemRenderer _particleSystemRenderer = null; - // private Rect _planeSize = new Rect(); - protected override void OnAwake() { type = ICLOiSimPlugin.Type.NONE; - - modelName = "ParticleSystem"; - partsName = pluginName; + _modelName = "World"; + _partsName = this.GetType().Name; _particleSystem = this.gameObject.GetComponent(); _particleSystemRenderer = this.gameObject.GetComponent(); diff --git a/Assets/Scripts/CLOiSimPlugins/RealSensePlugin.cs b/Assets/Scripts/CLOiSimPlugins/RealSensePlugin.cs index 190d625b..0fece0ee 100644 --- a/Assets/Scripts/CLOiSimPlugins/RealSensePlugin.cs +++ b/Assets/Scripts/CLOiSimPlugins/RealSensePlugin.cs @@ -8,20 +8,20 @@ using System.Collections.Generic; using messages = cloisim.msgs; using Any = cloisim.msgs.Any; -using UnityEngine; public class RealSensePlugin : CLOiSimMultiPlugin { - private SensorDevices.Camera[] cameras = null; - private SensorDevices.IMU imu = null; - private List> activatedModules = new List>(); + private SensorDevices.Camera[] _cameras = null; + private SensorDevices.IMU _imu = null; + private List> _activatedModules = new List>(); protected override void OnAwake() { type = ICLOiSimPlugin.Type.REALSENSE; - cameras = GetComponentsInChildren(); - imu = GetComponentInChildren(); - partsName = name; + _partsName = name; + + _cameras = GetComponentsInChildren(); + _imu = GetComponentInChildren(); } protected override void OnStart() @@ -71,33 +71,33 @@ protected override void OnStart() private void AddImuPlugin(in string name) { - if (imu.name.Equals(name)) + if (_imu.name.Equals(name)) { - var plugin = imu.gameObject.AddComponent(); + _imu.SetSubParts(true); + var plugin = _imu.gameObject.AddComponent(); plugin.ChangePluginType(ICLOiSimPlugin.Type.REALSENSE); + plugin.PartsName = _partsName; plugin.SubPartsName = name; - imu.SetSubParts(true); - - AddCLOiSimPlugin(name, plugin); - activatedModules.Add(new Tuple("imu", name)); + AddPlugin(name, plugin); + _activatedModules.Add(new Tuple("imu", name)); } } private CameraPlugin FindAndAddCameraPlugin(in string name) { - foreach (var camera in cameras) + foreach (var camera in _cameras) { if (camera.name.Equals(name)) { + camera.SetSubParts(true); var plugin = camera.gameObject.AddComponent(); plugin.ChangePluginType(ICLOiSimPlugin.Type.REALSENSE); + plugin.PartsName = _partsName; plugin.SubPartsName = name; - camera.SetSubParts(true); - - AddCLOiSimPlugin(name, plugin); - activatedModules.Add(new Tuple("camera", name)); + AddPlugin(name, plugin); + _activatedModules.Add(new Tuple("camera", name)); return plugin; } } @@ -135,7 +135,7 @@ private void SetModuleListInfoResponse(ref DeviceMessage msModuleInfo) modulesInfo.Name = "activated_modules"; modulesInfo.Value = new Any { Type = Any.ValueType.None }; - foreach (var module in activatedModules) + foreach (var module in _activatedModules) { var moduleInfo = new messages.Param(); moduleInfo.Name = "module"; diff --git a/Assets/Scripts/CLOiSimPlugins/SegmentationCameraPlugin.cs b/Assets/Scripts/CLOiSimPlugins/SegmentationCameraPlugin.cs index db3d4e11..787bd2a5 100644 --- a/Assets/Scripts/CLOiSimPlugins/SegmentationCameraPlugin.cs +++ b/Assets/Scripts/CLOiSimPlugins/SegmentationCameraPlugin.cs @@ -24,8 +24,6 @@ protected override void OnAwake() { Debug.LogError("SensorDevices.SegmentationCamera is missing."); } - - partsName = DeviceHelper.GetPartName(gameObject); } protected override void OnPluginLoad() diff --git a/Assets/Scripts/CLOiSimPlugins/SonarPlugin.cs b/Assets/Scripts/CLOiSimPlugins/SonarPlugin.cs index 20673226..b2f17ee1 100644 --- a/Assets/Scripts/CLOiSimPlugins/SonarPlugin.cs +++ b/Assets/Scripts/CLOiSimPlugins/SonarPlugin.cs @@ -14,9 +14,9 @@ public class SonarPlugin : CLOiSimPlugin protected override void OnAwake() { type = ICLOiSimPlugin.Type.SONAR; + sonar = gameObject.GetComponent(); attachedDevices.Add("SONAR", sonar); - partsName = DeviceHelper.GetPartName(gameObject); } protected override void OnStart() diff --git a/Assets/Scripts/Core/Modules/BridgeManager.cs b/Assets/Scripts/Core/Modules/BridgeManager.cs index 75c031bc..b708722f 100644 --- a/Assets/Scripts/Core/Modules/BridgeManager.cs +++ b/Assets/Scripts/Core/Modules/BridgeManager.cs @@ -183,14 +183,16 @@ public static bool IsAvailablePort(in ushort port) return true; } - private static string MakeHashKey(in string modelName, in string partsName, in string subPartsName) + private static string MakeHashKey(params string[] data) { - return modelName + partsName + subPartsName; + return string.Join("", data); } - public static bool AllocateDevice(in string deviceType, in string modelName, in string partsName, in string subPartsName, out string hashKey, out ushort port) + public static bool AllocateDevice( + in string deviceType, in string modelName, in string partsName, in string subPartsNameAndKey, + out string hashKey, out ushort port) { - hashKey = MakeHashKey(modelName, partsName, subPartsName); + hashKey = MakeHashKey(modelName, partsName, subPartsNameAndKey); if (string.IsNullOrEmpty(hashKey)) { @@ -209,19 +211,19 @@ public static bool AllocateDevice(in string deviceType, in string modelName, in { if (partsMapTable.TryGetValue(partsName, out var portsMapTable)) { - portsMapTable.Add(subPartsName, port); + portsMapTable.Add(subPartsNameAndKey, port); } else { var newPortsMapTable = new Dictionary(); - newPortsMapTable.Add(subPartsName, port); + newPortsMapTable.Add(subPartsNameAndKey, port); partsMapTable.Add(partsName, newPortsMapTable); } } else { var portsMapTable = new Dictionary(); - portsMapTable.Add(subPartsName, port); + portsMapTable.Add(subPartsNameAndKey, port); var newPartsMapTable = new Dictionary>(); newPartsMapTable.Add(partsName, portsMapTable); @@ -231,7 +233,7 @@ public static bool AllocateDevice(in string deviceType, in string modelName, in else { var portsMapTable = new Dictionary(); - portsMapTable.Add(subPartsName, port); + portsMapTable.Add(subPartsNameAndKey, port); var partsMapTable = new Dictionary>(); partsMapTable.Add(partsName, portsMapTable); diff --git a/Assets/Scripts/Core/SimulationWorld.cs b/Assets/Scripts/Core/SimulationWorld.cs index c8242c05..51433986 100644 --- a/Assets/Scripts/Core/SimulationWorld.cs +++ b/Assets/Scripts/Core/SimulationWorld.cs @@ -13,12 +13,11 @@ public class SimulationWorld : CLOiSimPlugin protected override void OnAwake() { type = ICLOiSimPlugin.Type.WORLD; + _modelName = "World"; + _partsName = this.GetType().Name; clock = gameObject.GetComponent(); attachedDevices.Add("Clock", clock); - - modelName = "World"; - partsName = "cloisim"; } protected override void OnStart() diff --git a/Assets/Scripts/Devices/Modules/Base/DeviceHelper.cs b/Assets/Scripts/Devices/Modules/Base/DeviceHelper.cs index 985141ae..a43ea601 100644 --- a/Assets/Scripts/Devices/Modules/Base/DeviceHelper.cs +++ b/Assets/Scripts/Devices/Modules/Base/DeviceHelper.cs @@ -13,6 +13,8 @@ public static partial class DeviceHelper { private static Clock globalClock = null; + private static double Sec2NSec = 1e+9; + private static double NSec2Sec = 1 / Sec2NSec; private static SphericalCoordinates globalSphericalCoordinates = null; @@ -38,7 +40,7 @@ public static SphericalCoordinates GetGlobalSphericalCoordinates() return globalSphericalCoordinates; } - public static string GetModelName(in GameObject targetObject, in bool searchOnlyOneDepth = false) + public static string GetModelName(in GameObject targetObject) { try { @@ -49,8 +51,7 @@ public static string GetModelName(in GameObject targetObject, in bool searchOnly nextObject = targetObject.GetComponentInParent(); } - if (searchOnlyOneDepth == false && nextObject != null && - !nextObject.CompareTag("Actor")) + if (nextObject != null && !nextObject.CompareTag("Actor")) { while (!SDF2Unity.IsRootModel(nextObject.transform)) { @@ -77,9 +78,32 @@ public static string GetModelName(in GameObject targetObject, in bool searchOnly } } - public static string GetPartName(in GameObject targetObject) + public static string GetPartsName(in GameObject targetObject) { - return GetModelName(targetObject, true); + try + { + if (targetObject.CompareTag("Model")) + { + return targetObject.name; + } + else + { + var linkHelper = targetObject.GetComponentInParent(); + if (linkHelper.transform.parent.CompareTag("Link")) + { + return linkHelper.transform.parent.name; // link name + } + else + { + return linkHelper.Model.name; // model name + } + } + } + catch + { + Debug.LogError("Thee is no parent object model"); + return string.Empty; + } } [DllImport("StdHash")] @@ -98,12 +122,12 @@ public static void Set(this messages.Time msg, in float time) } msg.Sec = (int)time; - msg.Nsec = (int)((time - (double)msg.Sec) * 1e+9); + msg.Nsec = (int)((time - (double)msg.Sec) * Sec2NSec); } public static float Get(this messages.Time msg) { - return (float)msg.Sec + ((float)msg.Nsec / (float)1e-9); + return (float)((double)msg.Sec + ((double)msg.Nsec * NSec2Sec)); } public static void SetCurrentTime(this messages.Time msg, in bool useRealTime = false) @@ -115,7 +139,7 @@ public static void SetCurrentTime(this messages.Time msg, in bool useRealTime = var timeNow = (useRealTime) ? GetGlobalClock().RealTime : GetGlobalClock().SimTime; msg.Sec = (int)timeNow; - msg.Nsec = (int)((timeNow - (double)msg.Sec) * 1e+9); + msg.Nsec = (int)((timeNow - (double)msg.Sec) * Sec2NSec); } public static void Set(this messages.Vector3d vector3d, in Vector3 position) diff --git a/Assets/Scripts/Devices/Modules/Motor/SelfBalanceControl/SelfBalancedDrive.cs b/Assets/Scripts/Devices/Modules/Motor/SelfBalanceControl/SelfBalancedDrive.cs index c577179e..f36fc172 100644 --- a/Assets/Scripts/Devices/Modules/Motor/SelfBalanceControl/SelfBalancedDrive.cs +++ b/Assets/Scripts/Devices/Modules/Motor/SelfBalanceControl/SelfBalancedDrive.cs @@ -23,6 +23,7 @@ public class SelfBalancedDrive : MotorControl #region Body Control private double _commandTargetBody = 0; // in deg + private double _adjustBodyRotation = 1.88; #endregion #region Roll/Height Control @@ -107,6 +108,12 @@ public bool Balancing set => _onBalancing = value; } + public double AdjustBodyRotation + { + get => _adjustBodyRotation; + set => _adjustBodyRotation = value; + } + public void DoResetPose() { _resetPose = true; @@ -225,8 +232,9 @@ public void ChangeWheelDriveType() public override void Drive(in float linearVelocity, in float angularVelocity) { const float BoostAngularSpeed = 3.0f; + _commandTwistLinear = linearVelocity; - _commandTwistAngular = SDF2Unity.CurveOrientationAngle(angularVelocity) * BoostAngularSpeed; + _commandTwistAngular = SDF2Unity.CurveOrientationAngle(angularVelocity); if (Math.Abs(_commandTwistLinear) < float.Epsilon || Math.Abs(_commandTwistAngular) < float.Epsilon) { @@ -236,11 +244,13 @@ public override void Drive(in float linearVelocity, in float angularVelocity) if (Math.Abs(_commandTwistLinear) > float.Epsilon && Math.Abs(_commandTwistAngular) > float.Epsilon) { - var ratio = _commandTwistAngular / _commandTwistLinear; - _commandTargetRollByDrive = ((ratio > 0) ? RollLimit.min : RollLimit.max) * -Math.Abs(ratio); + var ratio = Mathf.Clamp01(Mathf.Abs((float)(_commandTwistAngular/ _commandTwistLinear))); + _commandTargetRollByDrive = ((_commandTwistAngular > 0) ? RollLimit.max : RollLimit.min) * Math.Abs(ratio); // Debug.Log($"Command - linear: {_commandTwistLinear} angular: {_commandTwistAngular} ratio: {ratio} _commandTargetRollByDrive: {_commandTargetRollByDrive}"); } // Debug.Log($"Command - linear: {_commandTwistLinear} angular: {_commandTwistAngular} pitch: {PitchTarget}"); + + _commandTwistAngular *= BoostAngularSpeed; } private void UpdatePitchProfiler() @@ -291,8 +301,6 @@ private void AdjustHeadsetByPitch(in double currentPitch, in float duration) // Debug.LogWarning("Adjusting head by pitch"); } - private double adjustBody = 1.84; - private VectorXd ControlHipAndLeg(in double currentPitch) { var hipTarget = _commandTargetHeight * 0.5; @@ -301,7 +309,7 @@ private VectorXd ControlHipAndLeg(in double currentPitch) _commandHipTarget.x = hipTarget; _commandHipTarget.y = hipTarget; - _commandTargetBody = hipTarget * adjustBody; + _commandTargetBody = hipTarget * _adjustBodyRotation; // Debug.Log($"{hipTarget} {_commandTargetBody} "); _commandLegTarget.x = _commandTargetHeight; diff --git a/Assets/Scripts/Main.cs b/Assets/Scripts/Main.cs index 20177b39..be69d8a3 100644 --- a/Assets/Scripts/Main.cs +++ b/Assets/Scripts/Main.cs @@ -23,6 +23,8 @@ public class Main : MonoBehaviour [SerializeField] private string _worldFilename; + private string _loadedWorldFilePath = string.Empty; + [SerializeField] private List _modelRootDirectories = new List(); @@ -421,7 +423,7 @@ private IEnumerator LoadWorld() // Debug.Log("Hello CLOiSim World!!!!!"); Debug.Log("Target World: " + _worldFilename); - if (_sdfRoot.DoParse(out var world, _worldFilename)) + if (_sdfRoot.DoParse(out var world, out _loadedWorldFilePath, _worldFilename)) { SDF.Import.Util.RootModels = _worldRoot; @@ -455,7 +457,7 @@ public void SaveWorld() var worldSaver = new WorldSaver(saveDoc); worldSaver.Update(); - _sdfRoot.Save(); + _sdfRoot.Save(_loadedWorldFilePath); } void LateUpdate() diff --git a/Assets/Scripts/Tools/SDF/Parser/Joint.cs b/Assets/Scripts/Tools/SDF/Parser/Joint.cs index 63d61352..8b9b68bc 100644 --- a/Assets/Scripts/Tools/SDF/Parser/Joint.cs +++ b/Assets/Scripts/Tools/SDF/Parser/Joint.cs @@ -121,7 +121,7 @@ public class ODE private Physics physics = new Physics(); - // private Sensors sensors = null; + private Sensors _sensors = null; public string ParentLinkName => parent; @@ -139,6 +139,8 @@ public Joint(XmlNode _node) protected override void ParseElements() { + _sensors = new Sensors(root); + parent = GetValue("parent"); child = GetValue("child"); diff --git a/Assets/Scripts/Tools/SDF/Parser/Root.cs b/Assets/Scripts/Tools/SDF/Parser/Root.cs index 5567b155..f157df61 100644 --- a/Assets/Scripts/Tools/SDF/Parser/Root.cs +++ b/Assets/Scripts/Tools/SDF/Parser/Root.cs @@ -50,16 +50,16 @@ public Root() Console.SetError(_loggerErr); } - public bool DoParse(out World world, in string worldFileName) + public bool DoParse(out World world, out string worldFilePath, in string worldFileName) { // Console.Write("Loading World File from SDF!!!!!"); world = null; + worldFilePath = string.Empty; if (worldFileName.Trim().Length <= 0) { return false; } - var worldFound = false; // Console.Write("World file, PATH: " + worldFileName); foreach (var worldPath in worldDefaultPaths) { @@ -80,28 +80,22 @@ public bool DoParse(out World world, in string worldFileName) // Console.Write("Load World"); var worldNode = _doc.SelectSingleNode("/sdf/world"); world = new World(worldNode); - worldFound = true; + worldFilePath = worldPath; - var infoMessage = "World(" + worldFileName + ") is loaded."; - _logger.Write(infoMessage); + _logger.Write($"World({worldFileName}) is loaded."); // _logger.SetShowOnDisplayOnce(); - break; + return true; } catch (XmlException ex) { - var errorMessage = "Failed to Load World(" + fullFilePath + ") - " + ex.Message; _loggerErr.SetShowOnDisplayOnce(); - _loggerErr.Write(errorMessage); + _loggerErr.Write($"Failed to Load World({fullFilePath}) - {ex.Message}"); } } } - if (!worldFound) - { - _loggerErr.Write("World file not exist: " + worldFileName); - } - - return worldFound; + _loggerErr.Write("World file not exist: " + worldFileName); + return false; } public bool DoParse(out Model model, in string modelFullPath, in string modelFileName) @@ -191,7 +185,7 @@ public void UpdateResourceModelTable() } catch (XmlException e) { - Console.Write("Failed to Load model file(" + modelConfig + ") - " + e.Message); + Console.Write($"Failed to Load model file({modelConfig}) - {e.Message}"); continue; } @@ -210,7 +204,7 @@ public void UpdateResourceModelTable() { // Console.Write(version); // Console.Write(modelNode); - var sdfNode = modelNode.SelectSingleNode("sdf[@version=" + version + " or not(@version)]"); + var sdfNode = modelNode.SelectSingleNode($"sdf[@version={version} or not(@version)]"); if (sdfNode != null) { sdfFileName = sdfNode.InnerText; @@ -222,7 +216,7 @@ public void UpdateResourceModelTable() if (string.IsNullOrEmpty(sdfFileName)) { - Console.Write(modelName + ": SDF FileName is empty!!"); + Console.Write($"{modelName}: SDF FileName is empty!!"); continue; } @@ -403,31 +397,31 @@ private void StoreOriginalModelName(in XmlDocument targetDoc, in string modelNam } #endregion - private XmlNode GetIncludedModel(XmlNode included_node) + private XmlNode GetIncludedModel(XmlNode includedNode) { - var uri_node = included_node.SelectSingleNode("uri"); - if (uri_node == null) + var uriNode = includedNode.SelectSingleNode("uri"); + if (uriNode == null) { Console.Write("uri is empty."); return null; } - var nameNode = included_node.SelectSingleNode("name"); + var nameNode = includedNode.SelectSingleNode("name"); var name = (nameNode == null) ? null : nameNode.InnerText; - var staticNode = included_node.SelectSingleNode("static"); + var staticNode = includedNode.SelectSingleNode("static"); var isStatic = (staticNode == null) ? null : staticNode.InnerText; - var placementFrameNode = included_node.SelectSingleNode("placement_frame"); + var placementFrameNode = includedNode.SelectSingleNode("placement_frame"); var placementFrame = (placementFrameNode == null) ? null : placementFrameNode.InnerText; - var poseNode = included_node.SelectSingleNode("pose"); + var poseNode = includedNode.SelectSingleNode("pose"); var pose = (poseNode == null) ? null : poseNode.InnerText; - // var pluginNode = included_node.SelectSingleNode("plugin"); + var pluginNode = includedNode.SelectSingleNode("plugin"); // var plugin = (pluginNode == null) ? null : pluginNode.InnerText; - var uri = uri_node.InnerText; + var uri = uriNode.InnerText; var modelName = uri.Replace(ProtocolModel, string.Empty); if (resourceModelTable.TryGetValue(modelName, out var value)) @@ -448,9 +442,8 @@ private XmlNode GetIncludedModel(XmlNode included_node) } catch (XmlException e) { - var errorMessage = "Failed to Load included model(" + modelName + ") file - " + e.Message; _loggerErr.SetShowOnDisplayOnce(); - _loggerErr.Write(errorMessage); + _loggerErr.Write($"Failed to Load included model({modelName}) file - {e.Message}"); return null; } @@ -473,16 +466,16 @@ private XmlNode GetIncludedModel(XmlNode included_node) // Edit custom parameter if (nameNode != null) { - sdfNode.Attributes["name"].Value = name; + attributes.GetNamedItem("name").Value = name; } if (poseNode != null) { - if (sdfNode.SelectSingleNode("pose") != null) + var poseElem = sdfNode.SelectSingleNode("pose"); + if (poseElem != null) { - sdfNode.SelectSingleNode("pose").InnerText = pose; + poseElem.InnerText = pose; } - else { var elem = sdfNode.OwnerDocument.CreateElement("pose"); @@ -493,9 +486,10 @@ private XmlNode GetIncludedModel(XmlNode included_node) if (staticNode != null) { - if (sdfNode.SelectSingleNode("static") != null) + var staticElem = sdfNode.SelectSingleNode("static"); + if (staticElem != null) { - sdfNode.SelectSingleNode("static").InnerText = isStatic; + staticElem.InnerText = isStatic; } else { @@ -505,16 +499,20 @@ private XmlNode GetIncludedModel(XmlNode included_node) } } + if (pluginNode != null) + { + sdfNode.InsertBefore(pluginNode, sdfNode.LastChild); + } + return sdfNode; } - public void Save() + public void Save(in string filePath = "") { var fileName = Path.GetFileNameWithoutExtension(_worldFileName); var datetime = DateTime.Now.ToString("yyMMddHHmmss"); // DateTime.Now.ToString("yyyyMMddHHmmss"); - var saveName = fileName + datetime + ".world"; - + var saveName = $"{filePath}/{fileName}{datetime}.world"; _originalDoc.Save(saveName); Console.Write($"Worldfile Saved: {saveName}"); @@ -523,8 +521,8 @@ public void Save() public void Print() { // Print all SDF contents - StringWriter sw = new StringWriter(); - XmlTextWriter xw = new XmlTextWriter(sw); + var sw = new StringWriter(); + var xw = new XmlTextWriter(sw); _doc.WriteTo(xw); Console.Write(sw.ToString()); } diff --git a/Assets/Scripts/UI/UIController.cs b/Assets/Scripts/UI/UIController.cs index 18ebb684..cf597a6d 100644 --- a/Assets/Scripts/UI/UIController.cs +++ b/Assets/Scripts/UI/UIController.cs @@ -4,13 +4,9 @@ * SPDX-License-Identifier: MIT */ -using System; -using System.Collections; -using System.Collections.Generic; using UnityEngine; using UnityEngine.UIElements; - public class UIController : MonoBehaviour { private UIDocument _uiDocument = null; diff --git a/Packages/manifest.json b/Packages/manifest.json index c4591b58..d927059d 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -3,7 +3,7 @@ "com.unity.ai.navigation": "1.1.5", "com.unity.ide.vscode": "1.2.5", "com.unity.mathematics": "1.2.6", - "com.unity.performance.profile-analyzer": "1.2.2", + "com.unity.performance.profile-analyzer": "1.2.3", "com.unity.render-pipelines.universal": "14.0.11", "com.unity.robotics.vhacd": "https://github.com/Unity-Technologies/VHACD.git?path=/com.unity.robotics.vhacd", "com.unity.searcher": "4.9.2", @@ -28,6 +28,7 @@ "com.unity.modules.umbra": "1.0.0", "com.unity.modules.unityanalytics": "1.0.0", "com.unity.modules.unitywebrequestwww": "1.0.0", + "com.unity.modules.video": "1.0.0", "com.unity.modules.wind": "1.0.0" } } diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index fd6c6524..12a3f9e4 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -34,7 +34,7 @@ "url": "https://packages.unity.com" }, "com.unity.performance.profile-analyzer": { - "version": "1.2.2", + "version": "1.2.3", "depth": 0, "source": "registry", "dependencies": {}, @@ -310,6 +310,16 @@ "com.unity.modules.imageconversion": "1.0.0" } }, + "com.unity.modules.video": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.audio": "1.0.0", + "com.unity.modules.ui": "1.0.0", + "com.unity.modules.unitywebrequest": "1.0.0" + } + }, "com.unity.modules.wind": { "version": "1.0.0", "depth": 0, diff --git a/ProjectSettings/GraphicsSettings.asset b/ProjectSettings/GraphicsSettings.asset index 40740aee..019b5420 100644 --- a/ProjectSettings/GraphicsSettings.asset +++ b/ProjectSettings/GraphicsSettings.asset @@ -32,6 +32,7 @@ GraphicsSettings: - {fileID: 4800000, guid: 419a697b1455619dea4cc9d729b3d0c8, type: 3} - {fileID: 4800000, guid: 53ff4d2ede887e2d0becbbf9a26eb2c9, type: 3} - {fileID: 4800000, guid: c4375bff1dff4da53a01e7b4cebbf573, type: 3} + - {fileID: 4800000, guid: deae5ca476ee55d65b15a5f91a73287d, type: 3} m_PreloadedShaders: - {fileID: 20000000, guid: 444c3b2060d68fa04a081d66c72c2066, type: 2} m_PreloadShadersBatchTimeLimit: -1 diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 07b50378..d5d8e763 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -140,7 +140,7 @@ PlayerSettings: loadStoreDebugModeEnabled: 0 visionOSBundleVersion: 1.0 tvOSBundleVersion: 1.0 - bundleVersion: 4.9.4 + bundleVersion: 4.9.5 preloadedAssets: [] metroInputSource: 0 wsaTransparentSwapchain: 0 diff --git a/ProjectSettings/QualitySettings.asset b/ProjectSettings/QualitySettings.asset index 69643542..36272802 100644 --- a/ProjectSettings/QualitySettings.asset +++ b/ProjectSettings/QualitySettings.asset @@ -172,7 +172,7 @@ QualitySettings: globalTextureMipmapLimit: 0 textureMipmapLimitSettings: [] anisotropicTextures: 2 - antiAliasing: 4 + antiAliasing: 0 softParticles: 1 softVegetation: 1 realtimeReflectionProbes: 1