Interactions
This commit is contained in:
parent
22cdc782f9
commit
4f6c151e25
31 changed files with 498 additions and 12 deletions
46
src/substance_display.gd
Normal file
46
src/substance_display.gd
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
extends MeshInstance3D
|
||||
|
||||
enum DisplayType{
|
||||
Fluid,
|
||||
Solid,
|
||||
}
|
||||
|
||||
@export var display_type: DisplayType
|
||||
|
||||
func update_material(substances: Array[RuntimeSubstanceData]) -> void:
|
||||
var mat: StandardMaterial3D = material_override
|
||||
if len(substances) == 0:
|
||||
visible = false
|
||||
return
|
||||
else:
|
||||
visible = true
|
||||
|
||||
var total_weight = 0
|
||||
|
||||
for sub in substances:
|
||||
total_weight += sub.amount
|
||||
|
||||
var alpha: float = 0
|
||||
var color: Color = Color.WHITE
|
||||
|
||||
for sub in substances:
|
||||
if display_type == DisplayType.Fluid:
|
||||
alpha += sub.substance.liquid_transparency
|
||||
color = color.lerp(sub.substance.color,sub.amount/total_weight)
|
||||
if display_type == DisplayType.Fluid:
|
||||
alpha /= len(substances)
|
||||
color.a = alpha
|
||||
|
||||
mat.albedo_color = color
|
||||
|
||||
func update_material_unfiltered(substances: Array[RuntimeSubstanceData]):
|
||||
match display_type:
|
||||
DisplayType.Fluid:
|
||||
var fluids = substances.filter(filter_liquids)
|
||||
update_material(fluids)
|
||||
DisplayType.Solid:
|
||||
var solids = substances.filter(filter_solids)
|
||||
update_material(solids)
|
||||
|
||||
func filter_liquids(sub: RuntimeSubstanceData): return sub.substance.melting_point < sub.temperature or sub.substance.is_solution
|
||||
func filter_solids(sub: RuntimeSubstanceData): return sub.substance.melting_point > sub.temperature and not sub.substance.is_solution
|
||||
Loading…
Add table
Add a link
Reference in a new issue