-
Notifications
You must be signed in to change notification settings - Fork 6
/
Draw3D.cs
49 lines (36 loc) · 1.47 KB
/
Draw3D.cs
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
37
38
39
40
41
42
43
44
45
46
47
48
49
using Godot;
public static class Draw3D
{
public static MeshInstance3D Line(Vector3 pos1, Vector3 pos2, Color? color = null)
{
var meshInstance = new MeshInstance3D();
var immediateMesh = new ImmediateMesh();
var material = new StandardMaterial3D();
meshInstance.Mesh = immediateMesh;
meshInstance.CastShadow = GeometryInstance3D.ShadowCastingSetting.Off;
immediateMesh.SurfaceBegin(Mesh.PrimitiveType.Lines, material);
immediateMesh.SurfaceAddVertex(pos1);
immediateMesh.SurfaceAddVertex(pos2);
immediateMesh.SurfaceEnd();
material.ShadingMode = StandardMaterial3D.ShadingModeEnum.Unshaded;
material.AlbedoColor = color ?? Colors.WhiteSmoke;
(Engine.GetMainLoop() as SceneTree).Root.AddChild(meshInstance);
return meshInstance;
}
public static MeshInstance3D Point(Vector3 pos, float radius = 0.05f, Color? color = null)
{
var meshInstance = new MeshInstance3D();
var sphereMesh = new SphereMesh();
var material = new StandardMaterial3D();
meshInstance.Mesh = sphereMesh;
meshInstance.CastShadow = GeometryInstance3D.ShadowCastingSetting.Off;
meshInstance.Position = pos;
sphereMesh.Radius = radius;
sphereMesh.Height = radius * 2f;
sphereMesh.Material = material;
material.ShadingMode = StandardMaterial3D.ShadingModeEnum.Unshaded;
material.AlbedoColor = color ?? Colors.WhiteSmoke;
(Engine.GetMainLoop() as SceneTree).Root.AddChild(meshInstance);
return meshInstance;
}
}