Merge pull request #1892 from MoritzBrueckner/get-object-node
Get Object node: allow getting objects from other scenes
This commit is contained in:
commit
30088df19c
|
@ -1,7 +1,13 @@
|
|||
package armory.logicnode;
|
||||
|
||||
import iron.data.SceneFormat;
|
||||
import iron.object.Object;
|
||||
|
||||
class GetObjectNode extends LogicNode {
|
||||
|
||||
/** Scene from which to take the object **/
|
||||
public var property0: Null<String>;
|
||||
|
||||
public function new(tree: LogicTree) {
|
||||
super(tree);
|
||||
}
|
||||
|
@ -9,6 +15,35 @@ class GetObjectNode extends LogicNode {
|
|||
override function get(from: Int): Dynamic {
|
||||
var objectName: String = inputs[0].get();
|
||||
|
||||
return iron.Scene.active.getChild(objectName);
|
||||
if (property0 == null || property0 == iron.Scene.active.raw.name) {
|
||||
return iron.Scene.active.getChild(objectName);
|
||||
}
|
||||
|
||||
#if arm_json
|
||||
property0 += ".json";
|
||||
#elseif arm_compress
|
||||
property0 += ".lz4";
|
||||
#end
|
||||
|
||||
var outObj: Null<Object> = null;
|
||||
|
||||
// Create the object in the active scene if it is from an inactive scene
|
||||
iron.data.Data.getSceneRaw(property0, (rawScene: TSceneFormat) -> {
|
||||
var objData: Null<TObj> = null;
|
||||
|
||||
for (o in rawScene.objects) {
|
||||
if (o.name == objectName) {
|
||||
objData = o;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (objData == null) return;
|
||||
|
||||
iron.Scene.active.createObject(objData, rawScene, null, null, (newObj: Object) -> {
|
||||
outObj = newObj;
|
||||
});
|
||||
});
|
||||
|
||||
return outObj;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,12 +14,12 @@ class SpawnObjectNode extends LogicNode {
|
|||
}
|
||||
|
||||
override function run(from: Int) {
|
||||
|
||||
var objectName = "";
|
||||
var objectInput = inputs[1].get();
|
||||
if (objectInput == null) objectName = cast(inputs[1].node, ObjectNode).objectName;
|
||||
else objectName = objectInput.name;
|
||||
if (objectInput == null) return;
|
||||
|
||||
var objectName = objectInput.name;
|
||||
if (objectName == "") objectName = tree.object.name;
|
||||
|
||||
var m: Mat4 = inputs[2].get();
|
||||
matrices.push(m != null ? m.clone() : null);
|
||||
var spawnChildren: Bool = inputs.length > 3 ? inputs[3].get() : true; // TODO
|
||||
|
|
Loading…
Reference in a new issue