Skip to content

Commit

Permalink
Merge pull request #3116 from t3du/GetMaterialsNode
Browse files Browse the repository at this point in the history
GetMaterialsNode
  • Loading branch information
luboslenco authored Dec 27, 2024
2 parents 96ae00a + 2c3f1ee commit 4ef334d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
35 changes: 35 additions & 0 deletions armory/Sources/armory/logicnode/GetMaterialsNode.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package armory.logicnode;

import iron.object.MeshObject;
import iron.object.DecalObject;

class GetMaterialsNode extends LogicNode {

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

override function get(from: Int): Dynamic {

var object = inputs[0].get();

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 from == 0 ? [decal.material] : 1;
}
#end

if (Std.isOfType(object, MeshObject)) {
var mesh = cast(object, MeshObject);

if (mesh == null) return null;

return from == 0 ? mesh.materials : mesh.materials.length;
}

return null;
}
}
13 changes: 13 additions & 0 deletions armory/blender/arm/logicnode/material/LN_get_object_materials.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from arm.logicnode.arm_nodes import *

class GetMaterialsNode(ArmLogicTreeNode):
"""Returns the materials of the given object."""
bl_idname = 'LNGetMaterialsNode'
bl_label = 'Get Object Materials'
arm_version = 1

def arm_init(self, context):
self.add_input('ArmNodeSocketObject', 'Object')

self.add_output('ArmNodeSocketArray', 'Materials')
self.add_output('ArmIntSocket', 'Length')

0 comments on commit 4ef334d

Please sign in to comment.