Skip to content

Commit

Permalink
Merge pull request #2982 from t3du/world
Browse files Browse the repository at this point in the history
World Logic Nodes
  • Loading branch information
luboslenco committed Dec 20, 2023
2 parents efb9d75 + 2a1d86b commit 78de32b
Show file tree
Hide file tree
Showing 14 changed files with 304 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Sources/armory/logicnode/GetHosekWilkiePropertiesNode.hx
@@ -0,0 +1,27 @@
package armory.logicnode;

import iron.math.Vec4;

class GetHosekWilkiePropertiesNode extends LogicNode {

public function new(tree: LogicTree) {
super(tree);
}

override function get(from: Int): Dynamic {

var world = iron.Scene.active.world.raw;

return switch (from) {
case 0:
world.turbidity;
case 1:
world.ground_albedo;
case 2:
new Vec4(world.sun_direction[0], world.sun_direction[1], world.sun_direction[2]);
default:
null;
}
return null;
}
}
29 changes: 29 additions & 0 deletions Sources/armory/logicnode/GetNishitaPropertiesNode.hx
@@ -0,0 +1,29 @@
package armory.logicnode;

import iron.math.Vec4;

class GetNishitaPropertiesNode extends LogicNode {

public function new(tree: LogicTree) {
super(tree);
}

override function get(from: Int): Dynamic {

var world = iron.Scene.active.world.raw;

return switch (from) {
case 0:
world.nishita_density[0];
case 1:
world.nishita_density[1];
case 2:
world.nishita_density[2];
case 3:
new Vec4(world.sun_direction[0], world.sun_direction[1], world.sun_direction[2]);
default:
null;
}
return null;
}
}
12 changes: 12 additions & 0 deletions Sources/armory/logicnode/GetWorldStrengthNode.hx
@@ -0,0 +1,12 @@
package armory.logicnode;

class GetWorldStrengthNode extends LogicNode {

public function new(tree: LogicTree) {
super(tree);
}

override function get(from: Int): Dynamic {
return iron.Scene.active.world.raw.probe.strength;
}
}
41 changes: 41 additions & 0 deletions Sources/armory/logicnode/SetHosekWilkiePropertiesNode.hx
@@ -0,0 +1,41 @@
package armory.logicnode;

import armory.renderpath.HosekWilkie;
import iron.math.Vec4;

class SetHosekWilkiePropertiesNode extends LogicNode {

public var property0:String;

public function new(tree: LogicTree) {
super(tree);
}

override function run(from: Int) {

var world = iron.Scene.active.world;

if(property0 == 'Turbidity/Ground Albedo'){
world.raw.turbidity = inputs[1].get();
world.raw.ground_albedo = inputs[2].get();
}

if(property0 == 'Turbidity')
world.raw.turbidity = inputs[1].get();

if(property0 == 'Ground Albedo')
world.raw.ground_albedo = inputs[1].get();

if(property0 == 'Sun Direction'){
var vec:Vec4 = inputs[1].get();
world.raw.sun_direction[0] = vec.x;
world.raw.sun_direction[1] = vec.y;
world.raw.sun_direction[2] = vec.z;
}

HosekWilkie.recompute(world);

runOutput(0);

}
}
45 changes: 45 additions & 0 deletions Sources/armory/logicnode/SetNishitaPropertiesNode.hx
@@ -0,0 +1,45 @@
package armory.logicnode;

import armory.renderpath.Nishita;
import iron.math.Vec4;

class SetNishitaPropertiesNode extends LogicNode {

public var property0:String;

public function new(tree: LogicTree) {
super(tree);
}

override function run(from: Int) {

var world = iron.Scene.active.world;

if(property0 == 'Density'){
world.raw.nishita_density[0] = inputs[1].get();
world.raw.nishita_density[1] = inputs[2].get();
world.raw.nishita_density[2] = inputs[3].get();
}

if(property0 == 'Air')
world.raw.nishita_density[0] = inputs[1].get();

if(property0 == 'Dust')
world.raw.nishita_density[1] = inputs[1].get();

if(property0 == 'Ozone')
world.raw.nishita_density[2] = inputs[1].get();

if(property0 == 'Sun Direction'){
var vec:Vec4 = inputs[1].get();
world.raw.sun_direction[0] = vec.x;
world.raw.sun_direction[1] = vec.y;
world.raw.sun_direction[2] = vec.z;
}

Nishita.recompute(world);

runOutput(0);

}
}
16 changes: 16 additions & 0 deletions Sources/armory/logicnode/SetWorldStrengthNode.hx
@@ -0,0 +1,16 @@
package armory.logicnode;

class SetWorldStrengthNode extends LogicNode {

public function new(tree: LogicTree) {
super(tree);
}

override function run(from: Int) {

iron.Scene.active.world.raw.probe.strength = inputs[1].get();

runOutput(0);

}
}
1 change: 1 addition & 0 deletions blender/arm/logicnode/__init__.py
Expand Up @@ -34,6 +34,7 @@ def init_categories():
arm_nodes.add_category('Camera', icon='OUTLINER_OB_CAMERA', section="data")
arm_nodes.add_category('Material', icon='MATERIAL', section="data")
arm_nodes.add_category('Light', icon='LIGHT', section="data")
arm_nodes.add_category('World', icon='WORLD', section="data")
arm_nodes.add_category('Object', icon='OBJECT_DATA', section="data")
arm_nodes.add_category('Scene', icon='SCENE_DATA', section="data")
arm_nodes.add_category('Trait', icon='NODETREE', section="data")
Expand Down
12 changes: 12 additions & 0 deletions blender/arm/logicnode/world/LN_get_hosekwilkie_properties.py
@@ -0,0 +1,12 @@
from arm.logicnode.arm_nodes import *

class GetHosekWilkiePropertiesNode(ArmLogicTreeNode):
"""Gets the HosekWilkie properties."""
bl_idname = 'LNGetHosekWilkiePropertiesNode'
bl_label = 'Get HosekWilkie Properties'
arm_version = 1

def arm_init(self, context):
self.add_output('ArmFloatSocket', 'Turbidity')
self.add_output('ArmFloatSocket', 'Ground Albedo')
self.add_output('ArmVectorSocket', 'Sun Direction')
14 changes: 14 additions & 0 deletions blender/arm/logicnode/world/LN_get_nishita_properties.py
@@ -0,0 +1,14 @@
from arm.logicnode.arm_nodes import *

class GetNishitaPropertiesNode(ArmLogicTreeNode):
"""Gets the Nishita properties."""
bl_idname = 'LNGetNishitaPropertiesNode'
bl_label = 'Get Nishita Properties'
arm_version = 1

def arm_init(self, context):
self.add_output('ArmFloatSocket', 'Air')
self.add_output('ArmFloatSocket', 'Dust')
self.add_output('ArmFloatSocket', 'Ozone')
self.add_output('ArmVectorSocket', 'Sun Direction')

10 changes: 10 additions & 0 deletions blender/arm/logicnode/world/LN_get_world_strength.py
@@ -0,0 +1,10 @@
from arm.logicnode.arm_nodes import *

class GetWorldStrengthNode(ArmLogicTreeNode):
"""Gets the strength of the given World."""
bl_idname = 'LNGetWorldStrengthNode'
bl_label = 'Get World Strength'
arm_version = 1

def arm_init(self, context):
self.add_output('ArmFloatSocket', 'Strength')
38 changes: 38 additions & 0 deletions blender/arm/logicnode/world/LN_set_hosekwilkie_properties.py
@@ -0,0 +1,38 @@
from arm.logicnode.arm_nodes import *

class SetHosekWilkiePropertiesNode(ArmLogicTreeNode):
"""Sets the HosekWilkie properties."""
bl_idname = 'LNSetHosekWilkiePropertiesNode'
bl_label = 'Set HosekWilkie Properties'
arm_version = 1

def remove_extra_inputs(self, context):
while len(self.inputs) > 1:
self.inputs.remove(self.inputs[-1])
if self.property0 == 'Turbidity/Ground Albedo':
self.add_input('ArmFloatSocket', 'Turbidity')
self.add_input('ArmFloatSocket', 'Ground Albedo')
if self.property0 == 'Turbidity':
self.add_input('ArmFloatSocket', 'Turbidity')
if self.property0 == 'Ground Albedo':
self.add_input('ArmFloatSocket', 'Ground Albedo')
if self.property0 == 'Sun Direction':
self.add_input('ArmVectorSocket', 'Sun Direction')

property0: HaxeEnumProperty(
'property0',
items = [('Turbidity/Ground Albedo', 'Turbidity/Ground Albedo', 'Turbidity, Ground Albedo'),
('Turbidity', 'Turbidity', 'Turbidity'),
('Ground Albedo', 'Ground Albedo', 'Ground Albedo'),
('Sun Direction', 'Sun Direction', 'Sun Direction')],
name='', default='Turbidity/Ground Albedo', update=remove_extra_inputs)

def arm_init(self, context):
self.add_input('ArmNodeSocketAction', 'In')
self.add_input('ArmFloatSocket', 'Turbidity')
self.add_input('ArmFloatSocket', 'Ground_Albedo')

self.add_output('ArmNodeSocketAction', 'Out')

def draw_buttons(self, context, layout):
layout.prop(self, 'property0')
43 changes: 43 additions & 0 deletions blender/arm/logicnode/world/LN_set_nishita_properties.py
@@ -0,0 +1,43 @@
from arm.logicnode.arm_nodes import *

class SetNishitaPropertiesNode(ArmLogicTreeNode):
"""Sets the Nishita properties"""
bl_idname = 'LNSetNishitaPropertiesNode'
bl_label = 'Set Nishita Properties'
arm_version = 1

def remove_extra_inputs(self, context):
while len(self.inputs) > 1:
self.inputs.remove(self.inputs[-1])
if self.property0 == 'Density':
self.add_input('ArmFloatSocket', 'Air')
self.add_input('ArmFloatSocket', 'Dust')
self.add_input('ArmFloatSocket', 'Ozone')
if self.property0 == 'Air':
self.add_input('ArmFloatSocket', 'Air')
if self.property0 == 'Dust':
self.add_input('ArmFloatSocket', 'Dust')
if self.property0 == 'Ozone':
self.add_input('ArmFloatSocket', 'Ozone')
if self.property0 == 'Sun Direction':
self.add_input('ArmVectorSocket', 'Sun Direction')

property0: HaxeEnumProperty(
'property0',
items = [('Density', 'Density', 'Air, Dust, Ozone'),
('Air', 'Air', 'Air'),
('Dust', 'Dust', 'Dust'),
('Ozone', 'Ozone', 'Ozone'),
('Sun Direction', 'Sun Direction', 'Sun Direction')],
name='', default='Density', update=remove_extra_inputs)

def arm_init(self, context):
self.add_input('ArmNodeSocketAction', 'In')
self.add_input('ArmFloatSocket', 'Air')
self.add_input('ArmFloatSocket', 'Dust')
self.add_input('ArmFloatSocket', 'Ozone')

self.add_output('ArmNodeSocketAction', 'Out')

def draw_buttons(self, context, layout):
layout.prop(self, 'property0')
13 changes: 13 additions & 0 deletions blender/arm/logicnode/world/LN_set_world_strength.py
@@ -0,0 +1,13 @@
from arm.logicnode.arm_nodes import *

class SetWorldStrengthNode(ArmLogicTreeNode):
"""Sets the strength of the given World."""
bl_idname = 'LNSetWorldStrengthNode'
bl_label = 'Set World Strength'
arm_version = 1

def arm_init(self, context):
self.add_input('ArmNodeSocketAction', 'In')
self.add_input('ArmFloatSocket', 'Strength')

self.add_output('ArmNodeSocketAction', 'Out')
3 changes: 3 additions & 0 deletions blender/arm/logicnode/world/__init__.py
@@ -0,0 +1,3 @@
from arm.logicnode.arm_nodes import add_node_section

add_node_section(name='default', category='world')

0 comments on commit 78de32b

Please sign in to comment.