summaryrefslogtreecommitdiff
path: root/AutoMeshInstance.cs
blob: 43c6748db79cd4e980cf9027b64de430e87094b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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);
    }
}