init.lua 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. local function register_entity(name, textures, backface_culling)
  2. core.register_entity("gltf:" .. name, {
  3. initial_properties = {
  4. visual = "mesh",
  5. mesh = "gltf_" .. name .. ".gltf",
  6. textures = textures,
  7. backface_culling = backface_culling,
  8. },
  9. })
  10. end
  11. -- These do not have texture coordinates; they simple render as black surfaces.
  12. register_entity("minimal_triangle", {}, false)
  13. register_entity("triangle_with_vertex_stride", {}, false)
  14. register_entity("triangle_without_indices", {}, false)
  15. do
  16. local cube_textures = {"gltf_cube.png"}
  17. register_entity("blender_cube", cube_textures)
  18. register_entity("blender_cube_scaled", cube_textures)
  19. register_entity("blender_cube_matrix_transform", cube_textures)
  20. core.register_entity("gltf:blender_cube_glb", {
  21. initial_properties = {
  22. visual = "mesh",
  23. mesh = "gltf_blender_cube.glb",
  24. textures = cube_textures,
  25. backface_culling = true,
  26. },
  27. })
  28. end
  29. register_entity("snow_man", {"gltf_snow_man.png"})
  30. register_entity("spider", {"gltf_spider.png"})
  31. core.register_entity("gltf:spider_animated", {
  32. initial_properties = {
  33. visual = "mesh",
  34. mesh = "gltf_spider_animated.gltf",
  35. textures = {"gltf_spider.png"},
  36. },
  37. on_activate = function(self)
  38. self.object:set_animation({x = 0, y = 140}, 1)
  39. end
  40. })
  41. core.register_entity("gltf:simple_skin", {
  42. initial_properties = {
  43. visual = "mesh",
  44. visual_size = vector.new(5, 5, 5),
  45. mesh = "gltf_simple_skin.gltf",
  46. textures = {},
  47. backface_culling = false
  48. },
  49. on_activate = function(self)
  50. self.object:set_animation({x = 0, y = 5.5}, 1)
  51. end
  52. })
  53. -- The claws rendering incorrectly from one side is expected behavior:
  54. -- They use an unsupported double-sided material.
  55. core.register_entity("gltf:frog", {
  56. initial_properties = {
  57. visual = "mesh",
  58. mesh = "gltf_frog.gltf",
  59. textures = {"gltf_frog.png"},
  60. backface_culling = false
  61. },
  62. on_activate = function(self)
  63. self.object:set_animation({x = 0, y = 0.75}, 1)
  64. end
  65. })
  66. core.register_node("gltf:frog", {
  67. description = "glTF frog, but it's a node",
  68. tiles = {{name = "gltf_frog.png", backface_culling = false}},
  69. drawtype = "mesh",
  70. mesh = "gltf_frog.gltf",
  71. })
  72. core.register_chatcommand("show_model", {
  73. params = "<model> [textures]",
  74. description = "Show a model (defaults to gltf models, for example '/show_model frog').",
  75. func = function(name, param)
  76. local model, textures = param:match"^(.-)%s+(.+)$"
  77. if not model then
  78. model = "gltf_" .. param .. ".gltf"
  79. textures = "gltf_" .. param .. ".png"
  80. end
  81. core.show_formspec(name, "gltf:model", table.concat{
  82. "formspec_version[7]",
  83. "size[10,10]",
  84. "model[0,0;10,10;model;", model, ";", textures, ";0,0;true;true;0,0;0]",
  85. })
  86. end,
  87. })