Add functionality to synchronise rendered terrain to position of the geom

This commit is contained in:
Bálint Hodossy
2023-12-05 18:49:32 +00:00
parent f5a2879f9d
commit 3e3687d022
2 changed files with 5 additions and 2 deletions
@@ -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<Vector3[], int[]> BuildMesh(){
return Tuple.Create(new Vector3[]{}, new int[]{});
return null;
}
public void DebugDraw(Transform transform){
+1 -1
View File
@@ -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}"));
}
}