init.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. core.register_entity("gltf:simple_skin_step", {
  54. initial_properties = {
  55. infotext = "Simple skin, but using STEP interpolation",
  56. visual = "mesh",
  57. visual_size = vector.new(5, 5, 5),
  58. mesh = "gltf_simple_skin_step.gltf",
  59. textures = {},
  60. backface_culling = false
  61. },
  62. on_activate = function(self)
  63. self.object:set_animation({x = 0, y = 5.5}, 1)
  64. end
  65. })
  66. -- The claws rendering incorrectly from one side is expected behavior:
  67. -- They use an unsupported double-sided material.
  68. core.register_entity("gltf:frog", {
  69. initial_properties = {
  70. visual = "mesh",
  71. mesh = "gltf_frog.gltf",
  72. textures = {"gltf_frog.png"},
  73. backface_culling = false
  74. },
  75. on_activate = function(self)
  76. self.object:set_animation({x = 0, y = 0.75}, 1)
  77. end
  78. })
  79. core.register_node("gltf:frog", {
  80. description = "glTF frog, but it's a node",
  81. tiles = {{name = "gltf_frog.png", backface_culling = false}},
  82. drawtype = "mesh",
  83. mesh = "gltf_frog.gltf",
  84. })
  85. core.register_chatcommand("show_model", {
  86. params = "<model> [textures]",
  87. description = "Show a model (defaults to gltf models, for example '/show_model frog').",
  88. func = function(name, param)
  89. local model, textures = param:match"^(.-)%s+(.+)$"
  90. if not model then
  91. model = "gltf_" .. param .. ".gltf"
  92. textures = "gltf_" .. param .. ".png"
  93. end
  94. core.show_formspec(name, "gltf:model", table.concat{
  95. "formspec_version[7]",
  96. "size[10,10]",
  97. "model[0,0;10,10;model;", model, ";", textures, ";0,0;true;true;0,0;0]",
  98. })
  99. end,
  100. })