nezvers

Godot MeshArray generation tool scrip

May 21st, 2021 (edited)
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. tool
  2. extends MeshInstance
  3.  
  4. var meshArray: = ArrayMesh.new()
  5.  
  6. export (bool) var generate:bool = false setget set_generate
  7.  
  8. var points: = [
  9. Vector3(-0.7, 0, -0.7),
  10. Vector3(-0.3, 0, 0.8),
  11. Vector3(0.8, 0, -0.3),
  12. Vector3(0, -1, 0),
  13. ]
  14.  
  15.  
  16. func set_generate(_value:bool)->void:
  17. generate = false
  18. var arr = []
  19. arr.resize(Mesh.ARRAY_MAX)
  20. var vertex: = PoolVector3Array(points)
  21. var indexes: = PoolIntArray([0,1,3,1,2,3,2,0,3,2,1,0 ])
  22. var normals: = []
  23. arr[Mesh.ARRAY_VERTEX] = vertex
  24. arr[Mesh.ARRAY_INDEX] = indexes
  25. for point in points:
  26. normals.append(point.normalized())
  27. arr[Mesh.ARRAY_NORMAL] = PoolVector3Array(normals)
  28.  
  29. meshArray.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arr)
  30. mesh = meshArray
  31.  
Add Comment
Please, Sign In to add comment