2017-04-04 23:11:31 +02:00
|
|
|
package armory.logicnode;
|
|
|
|
|
2017-11-20 15:16:52 +01:00
|
|
|
import iron.object.Object;
|
|
|
|
import iron.math.Mat4;
|
2017-10-22 21:18:01 +02:00
|
|
|
import armory.trait.physics.RigidBody;
|
2017-04-04 23:11:31 +02:00
|
|
|
|
2017-04-08 20:05:35 +02:00
|
|
|
class SpawnObjectNode extends LogicNode {
|
2017-04-04 23:11:31 +02:00
|
|
|
|
2019-12-19 23:54:08 +01:00
|
|
|
var object: Object;
|
|
|
|
var matrices: Array<Mat4> = [];
|
2017-04-04 23:11:31 +02:00
|
|
|
|
2019-12-19 23:54:08 +01:00
|
|
|
public function new(tree: LogicTree) {
|
2017-04-04 23:11:31 +02:00
|
|
|
super(tree);
|
|
|
|
}
|
|
|
|
|
2019-12-19 23:54:08 +01:00
|
|
|
override function run(from: Int) {
|
2017-11-22 23:42:39 +01:00
|
|
|
var objectInput = inputs[1].get();
|
2020-09-26 16:33:43 +02:00
|
|
|
if (objectInput == null) return;
|
|
|
|
|
|
|
|
var objectName = objectInput.name;
|
2017-11-23 00:11:16 +01:00
|
|
|
if (objectName == "") objectName = tree.object.name;
|
2020-09-26 16:33:43 +02:00
|
|
|
|
2019-12-19 23:54:08 +01:00
|
|
|
var m: Mat4 = inputs[2].get();
|
2018-11-13 21:54:55 +01:00
|
|
|
matrices.push(m != null ? m.clone() : null);
|
2019-12-19 23:54:08 +01:00
|
|
|
var spawnChildren: Bool = inputs.length > 3 ? inputs[3].get() : true; // TODO
|
2017-04-04 23:11:31 +02:00
|
|
|
|
2019-12-19 23:54:08 +01:00
|
|
|
iron.Scene.active.spawnObject(objectName, null, function(o: Object) {
|
2017-04-04 23:11:31 +02:00
|
|
|
object = o;
|
2018-11-13 19:47:26 +01:00
|
|
|
var matrix = matrices.pop(); // Async spawn in a loop, order is non-stable
|
2017-10-22 21:18:01 +02:00
|
|
|
if (matrix != null) {
|
|
|
|
object.transform.setMatrix(matrix);
|
|
|
|
#if arm_physics
|
|
|
|
var rigidBody = object.getTrait(RigidBody);
|
|
|
|
if (rigidBody != null) {
|
|
|
|
object.transform.buildMatrix();
|
|
|
|
rigidBody.syncTransform();
|
|
|
|
}
|
|
|
|
#end
|
|
|
|
}
|
2017-04-04 23:11:31 +02:00
|
|
|
object.visible = true;
|
2018-10-22 10:10:33 +02:00
|
|
|
runOutput(0);
|
2018-10-14 18:51:13 +02:00
|
|
|
}, spawnChildren);
|
2017-04-04 23:11:31 +02:00
|
|
|
}
|
|
|
|
|
2019-12-19 23:54:08 +01:00
|
|
|
override function get(from: Int): Dynamic {
|
2017-04-04 23:11:31 +02:00
|
|
|
return object;
|
|
|
|
}
|
|
|
|
}
|