Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @tool
- extends MeshInstance3D
- @export var Color_POI : StandardMaterial3D
- @export var Point_of_impact = Vector3.ZERO
- @export var Distance_Max = 5
- @export var Puissance_Multi = 1.0
- @export var Noisee : FastNoiseLite
- @export var CrushN = false
- @onready var Mesh_Pos = MeshInstance3D.new()
- @onready var Ball = SphereMesh.new()
- @export var Crush_Away = false
- @export var Without_noise = false
- @export var Pure_Distance = false
- @export var mesh_pos_for_dir = false
- # Called when the node enters the scene tree for the first time.
- func _ready():
- Mesh_Pos.mesh = Ball
- Mesh_Pos.set_surface_override_material(0,Color_POI)
- add_child(Mesh_Pos)
- pass # Replace with function body.
- # Called every frame. 'delta' is the elapsed time since the previous frame.
- func _process(delta):
- Mesh_Pos.mesh.height = (Distance_Max) *2.0
- Mesh_Pos.mesh.radius = (float(Distance_Max)/2.0) * 2.0
- # print(Mesh_Pos.mesh.height ," / ",Mesh_Pos.mesh.radius )
- Mesh_Pos.position = Point_of_impact
- if CrushN:
- Crush()
- CrushN = false
- pass
- func Crush():
- var spare_mesh = mesh.duplicate()
- var mdt = MeshDataTool.new()
- var numbre_surfaces = mesh.get_surface_count()
- print("il y a ", numbre_surfaces," surfaces")
- mesh.clear_surfaces()
- for a in numbre_surfaces:
- print("Travaille sur surface ", a)
- print(a ,"possède ",mdt.get_vertex_count() ," vertex")
- mdt.create_from_surface(spare_mesh,a)
- for i in range(mdt.get_vertex_count()):
- var vertex = mdt.get_vertex(i)
- # var distance = absf(Distance_Max - (Point_of_impact.distance_to(vertex)))
- var distance = 1 - (Point_of_impact.distance_to(vertex) / Distance_Max)
- distance = clampf(distance,0,1)
- if Pure_Distance:
- distance = (Distance_Max - Point_of_impact.distance_to(vertex))
- if Point_of_impact.distance_to(vertex) > Distance_Max:
- distance = 0
- # print(distance)
- var deform_x = Noisee.get_noise_3d(i,0,0)
- var deform_y = Noisee.get_noise_3d(0,i,0)
- var deform_z = Noisee.get_noise_3d(0,0,i)
- var crush_dir = (Point_of_impact - vertex)
- if mesh_pos_for_dir:
- crush_dir = (Point_of_impact)
- # crush_dir.y = 0
- crush_dir = crush_dir.normalized()
- var crush_pow = (absf(deform_x) * -crush_dir) * distance
- if Pure_Distance:
- crush_pow = -crush_dir * distance
- # print("verpos = ",vertex ,"dis = ",distance)
- if not Crush_Away:
- if not Without_noise:
- vertex.x += (deform_x * Puissance_Multi) * distance
- vertex.y += (deform_y * Puissance_Multi) * distance
- vertex.z += (deform_z * Puissance_Multi) * distance
- if Without_noise:
- vertex.x += ( Puissance_Multi) * distance
- vertex.y += ( Puissance_Multi) * distance
- vertex.z += ( Puissance_Multi) * distance
- else:
- vertex += (crush_pow * Puissance_Multi)
- mdt.set_vertex(i,vertex)
- mdt.commit_to_surface(mesh)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement