From 3e3687d022c0c23947926a154350dde76deb78a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Hodossy?= Date: Tue, 5 Dec 2023 18:49:32 +0000 Subject: [PATCH] Add functionality to synchronise rendered terrain to position of the geom --- unity/Runtime/Components/Shapes/MjHeightFieldShape.cs | 5 ++++- unity/Runtime/Tools/MjcfGenerationContext.cs | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/unity/Runtime/Components/Shapes/MjHeightFieldShape.cs b/unity/Runtime/Components/Shapes/MjHeightFieldShape.cs index 14597256..86b3fee9 100644 --- a/unity/Runtime/Components/Shapes/MjHeightFieldShape.cs +++ b/unity/Runtime/Components/Shapes/MjHeightFieldShape.cs @@ -36,8 +36,11 @@ public class MjHeightFieldShape : IMjShape public void ToMjcf(XmlElement mjcf, Transform transform){ ExportHeightMap(); + if(terrain.transform.parent != transform) Debug.LogWarning($"The terrain of heightfield {transform.name} needs to be parented to the Geom for proper rendering."); + else terrain.transform.localPosition = new Vector3(-HeightMapHeight*HeightMapScale.x / 2, terrain.transform.localPosition.y, -HeightMapWidth*HeightMapScale.z / 2); var scene = MjScene.Instance; var assetName = scene.GenerationContext.AddHeightFieldAsset(this); + mjcf.SetAttribute("hfield", assetName); } @@ -59,7 +62,7 @@ public class MjHeightFieldShape : IMjShape } public Tuple BuildMesh(){ - return Tuple.Create(new Vector3[]{}, new int[]{}); + return null; } public void DebugDraw(Transform transform){ diff --git a/unity/Runtime/Tools/MjcfGenerationContext.cs b/unity/Runtime/Tools/MjcfGenerationContext.cs index 454a6906..86fb9ae7 100644 --- a/unity/Runtime/Tools/MjcfGenerationContext.cs +++ b/unity/Runtime/Tools/MjcfGenerationContext.cs @@ -121,7 +121,7 @@ public class MjcfGenerationContext { mjcf.SetAttribute("content_type", "image/png"); mjcf.SetAttribute("file", hFieldComponent.FullHeightMapPath); - mjcf.SetAttribute("size", MjEngineTool.MakeLocaleInvariant($"{hFieldComponent.HeightMapScale.x*hFieldComponent.HeightMapHeight/2} {hFieldComponent.HeightMapScale.z * hFieldComponent.HeightMapWidth/2} {hFieldComponent.HeightMapScale.y*2} {hFieldComponent.terrain.transform.position.y}")); + mjcf.SetAttribute("size", MjEngineTool.MakeLocaleInvariant($"{hFieldComponent.HeightMapScale.x*hFieldComponent.HeightMapHeight/2} {hFieldComponent.HeightMapScale.z * hFieldComponent.HeightMapWidth/2} {hFieldComponent.HeightMapScale.y} {hFieldComponent.terrain.transform.localPosition.y}")); } }