From 71b3cd829f80de4c2cd3972d8bfd5ee470a5d180 Mon Sep 17 00:00:00 2001 From: Gone2Daly <71726742+Gone2Daly@users.noreply.github.com> Date: Sat, 22 Jul 2023 21:05:42 +0200 Subject: init_test --- .../zylann.hterrain/util/direct_mesh_instance.gd | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 game/addons/zylann.hterrain/util/direct_mesh_instance.gd (limited to 'game/addons/zylann.hterrain/util/direct_mesh_instance.gd') diff --git a/game/addons/zylann.hterrain/util/direct_mesh_instance.gd b/game/addons/zylann.hterrain/util/direct_mesh_instance.gd new file mode 100644 index 0000000..17c89c9 --- /dev/null +++ b/game/addons/zylann.hterrain/util/direct_mesh_instance.gd @@ -0,0 +1,65 @@ +@tool + +# Implementation of MeshInstance which doesn't use the scene tree + +var _mesh_instance := RID() +# Need to keep a reference so that the mesh RID doesn't get freed +var _mesh : Mesh + + +func _init(): + var rs = RenderingServer + _mesh_instance = rs.instance_create() + rs.instance_set_visible(_mesh_instance, true) + + +func _notification(p_what: int): + if p_what == NOTIFICATION_PREDELETE: + if _mesh_instance != RID(): + RenderingServer.free_rid(_mesh_instance) + _mesh_instance = RID() + + +func enter_world(world: World3D): + assert(_mesh_instance != RID()) + RenderingServer.instance_set_scenario(_mesh_instance, world.get_scenario()) + + +func exit_world(): + assert(_mesh_instance != RID()) + RenderingServer.instance_set_scenario(_mesh_instance, RID()) + + +func set_world(world: World3D): + if world != null: + enter_world(world) + else: + exit_world() + + +func set_transform(world_transform: Transform3D): + assert(_mesh_instance != RID()) + RenderingServer.instance_set_transform(_mesh_instance, world_transform) + + +func set_mesh(mesh: Mesh): + assert(_mesh_instance != RID()) + RenderingServer.instance_set_base(_mesh_instance, mesh.get_rid() if mesh != null else RID()) + _mesh = mesh + + +func set_material(material: Material): + assert(_mesh_instance != RID()) + RenderingServer.instance_geometry_set_material_override( \ + _mesh_instance, material.get_rid() if material != null else RID()) + + +func set_visible(visible: bool): + assert(_mesh_instance != RID()) + RenderingServer.instance_set_visible(_mesh_instance, visible) + + +func set_aabb(aabb: AABB): + assert(_mesh_instance != RID()) + RenderingServer.instance_set_custom_aabb(_mesh_instance, aabb) + -- cgit v1.2.3-56-ga3b1