armory/Sources/armory/logicnode/GetMaterialNode.hx

37 lines
699 B
Haxe
Raw Normal View History

2017-04-08 20:05:35 +02:00
package armory.logicnode;
2017-11-20 15:16:52 +01:00
import iron.object.MeshObject;
2021-10-31 23:03:25 +01:00
import iron.object.DecalObject;
2017-04-08 20:05:35 +02:00
class GetMaterialNode extends LogicNode {
2019-12-19 23:54:08 +01:00
public function new(tree: LogicTree) {
2017-04-08 20:05:35 +02:00
super(tree);
}
2019-12-19 23:54:08 +01:00
override function get(from: Int): Dynamic {
2017-04-08 20:05:35 +02:00
2021-10-31 23:03:25 +01:00
var object = inputs[0].get();
2017-04-08 20:05:35 +02:00
2021-10-31 23:03:25 +01:00
assert(Error, object != null, "The object input must not be null");
#if rp_decals
if (Std.isOfType(object, DecalObject)) {
var decal = cast(object, DecalObject);
return decal.material;
}
#end
if (Std.isOfType(object, MeshObject)) {
var mesh = cast(object, MeshObject);
var slot: Int = inputs[1].get();
if (mesh == null) return null;
return mesh.materials[slot];
}
return null;
2017-04-08 20:05:35 +02:00
}
}