3DLabel.gd 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. extends Spatial
  2. export var text = 'hello world'
  3. var textnode
  4. var letters_drawn = 0
  5. var mat
  6. export var color = Color8(100,100,100)
  7. var power = 6.0
  8. var rotspeed = 2.0
  9. class_name Label3D
  10. func _ready():
  11. prepare_material()
  12. make_text()
  13. func make_text():
  14. if textnode:
  15. textnode.queue_free()
  16. textnode = null
  17. letters_drawn = 0
  18. textnode = Spatial.new()
  19. add_child(textnode)
  20. textnode.translation=Vector3(-float(text.length())*6.0/2.0,0.0,0.0)
  21. for c in text:
  22. add_letter(c)
  23. func prepare_material():
  24. mat = SpatialMaterial.new()
  25. mat.emission_enabled=true
  26. mat.emission_energy = power
  27. mat.emission = color
  28. mat.albedo_color = ColorN("black")
  29. mat.albedo_texture = load("res://neon_test_texture0.png")
  30. func add_letter(ch):
  31. if ch == " ":
  32. letters_drawn+=1
  33. return
  34. if ch == "!": ch = "exclamation"
  35. if ch == ".": ch = "dot"
  36. if ch == ",": ch = "comma"
  37. if ch == ":": ch = "colon"
  38. if ch == "\"": ch = "quotes"
  39. if ch == "'": ch = "apo"
  40. if ch == "?": ch = "question"
  41. var m = MeshInstance.new()
  42. ch=ch.to_lower()
  43. m.mesh = load("res://AlphaVoxel/"+ch+".obj")
  44. textnode.add_child(m)
  45. m.set_surface_material(0,mat)
  46. m.translation = Vector3(letters_drawn*6.0,-5.0,0)
  47. letters_drawn+=1