-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3116 from t3du/GetMaterialsNode
GetMaterialsNode
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
armory/blender/arm/logicnode/material/LN_get_object_materials.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |