summaryrefslogtreecommitdiff
path: root/AutoMeshInstance.cs
diff options
context:
space:
mode:
Diffstat (limited to 'AutoMeshInstance.cs')
-rw-r--r--AutoMeshInstance.cs36
1 files changed, 36 insertions, 0 deletions
diff --git a/AutoMeshInstance.cs b/AutoMeshInstance.cs
new file mode 100644
index 0000000..43c6748
--- /dev/null
+++ b/AutoMeshInstance.cs
@@ -0,0 +1,36 @@
+using Godot;
+using System;
+
+/**
+* Used to auto-generate Meshes that are the same as collision objects, for convenience.
+* makes a new MeshInstance3D as a sibling (child of this object's parent)
+* and applies the same shape, tranform, and scale.
+*/
+public partial class AutoMeshInstance : CollisionShape3D
+{
+ public override void _Ready()
+ {
+ base._Ready();
+
+ MeshInstance3D mi = new MeshInstance3D();
+ if (Shape is BoxShape3D boxshp){
+ BoxMesh m = new BoxMesh();
+ m.Size = boxshp.Size;
+ mi.Mesh = m;
+ }
+ if (Shape is CylinderShape3D cylshp){
+ CylinderMesh m = new CylinderMesh();
+ m.TopRadius = cylshp.Radius;
+ m.BottomRadius = cylshp.Radius;
+ m.Height = cylshp.Height;
+ mi.Mesh = m;
+ }
+ if (Shape is CapsuleShape3D){}
+ if (Shape is SphereShape3D){}
+
+ mi.Rotation = Rotation;
+ mi.Position = Position;
+
+ GetParent().CallDeferred("add_child", mi);
+ }
+}