Fix physics node if arm_physics is false + cleanup
This commit is contained in:
parent
8a758bbe26
commit
6a3045477f
|
@ -1,13 +1,11 @@
|
||||||
package armory.logicnode;
|
package armory.logicnode;
|
||||||
|
|
||||||
import armory.trait.physics.PhysicsConstraint;
|
|
||||||
#if arm_physics
|
|
||||||
import armory.trait.physics.bullet.PhysicsConstraint.ConstraintType;
|
|
||||||
import armory.trait.physics.bullet.PhysicsConstraint.ConstraintAxis;
|
|
||||||
#end
|
|
||||||
import iron.object.Object;
|
import iron.object.Object;
|
||||||
import armory.trait.physics.RigidBody;
|
|
||||||
import armory.logicnode.PhysicsConstraintNode;
|
#if arm_physics
|
||||||
|
import armory.trait.physics.PhysicsConstraint;
|
||||||
|
import armory.trait.physics.bullet.PhysicsConstraint.ConstraintType;
|
||||||
|
#end
|
||||||
|
|
||||||
class AddPhysicsConstraintNode extends LogicNode {
|
class AddPhysicsConstraintNode extends LogicNode {
|
||||||
|
|
||||||
|
@ -21,115 +19,96 @@ class AddPhysicsConstraintNode extends LogicNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
override function run(from: Int) {
|
override function run(from: Int) {
|
||||||
var pivotObject:Object = inputs[1].get();
|
var pivotObject: Object = inputs[1].get();
|
||||||
rb1 = inputs[2].get();
|
rb1 = inputs[2].get();
|
||||||
rb2 = inputs[3].get();
|
rb2 = inputs[3].get();
|
||||||
var disableCollisions: Bool = inputs[4].get();
|
|
||||||
var breakable: Bool = inputs[5].get();
|
|
||||||
var breakingThreshold: Float = inputs[6].get();
|
|
||||||
var type: ConstraintType = 0;
|
|
||||||
|
|
||||||
if (pivotObject == null || rb1 == null || rb2 == null) return;
|
if (pivotObject == null || rb1 == null || rb2 == null) return;
|
||||||
|
|
||||||
#if arm_physics
|
#if arm_physics
|
||||||
|
|
||||||
|
var disableCollisions: Bool = inputs[4].get();
|
||||||
|
var breakable: Bool = inputs[5].get();
|
||||||
|
var breakingThreshold: Float = inputs[6].get();
|
||||||
|
var type: ConstraintType = 0;
|
||||||
|
|
||||||
var con: PhysicsConstraint = pivotObject.getTrait(PhysicsConstraint);
|
var con: PhysicsConstraint = pivotObject.getTrait(PhysicsConstraint);
|
||||||
if(con == null)
|
if (con == null) {
|
||||||
{
|
switch (property0) {
|
||||||
switch(property0)
|
case "Fixed": type = Fixed;
|
||||||
{
|
case "Point": type = Point;
|
||||||
case 'Fixed':
|
case "Hinge": type = Hinge;
|
||||||
type = Fixed;
|
case "Slider": type = Slider;
|
||||||
case 'Point':
|
case "Piston": type = Piston;
|
||||||
type = Point;
|
case "Generic Spring": type = Generic;
|
||||||
case 'Hinge':
|
|
||||||
type = Hinge;
|
|
||||||
case 'Slider':
|
|
||||||
type = Slider;
|
|
||||||
case 'Piston':
|
|
||||||
type = Piston;
|
|
||||||
case 'Generic Spring':
|
|
||||||
type = Generic;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(! breakable) breakingThreshold = 0.0;
|
if (!breakable) breakingThreshold = 0.0;
|
||||||
|
|
||||||
|
if (type != Generic) {
|
||||||
|
|
||||||
if(type != Generic) {
|
|
||||||
|
|
||||||
con = new PhysicsConstraint(rb1, rb2, type, disableCollisions, breakingThreshold);
|
con = new PhysicsConstraint(rb1, rb2, type, disableCollisions, breakingThreshold);
|
||||||
|
|
||||||
switch (type)
|
switch (type) {
|
||||||
{
|
|
||||||
case Hinge:
|
case Hinge:
|
||||||
var setLimit:Bool = inputs[7].get();
|
var setLimit: Bool = inputs[7].get();
|
||||||
var low:Float = inputs[8].get();
|
var low: Float = inputs[8].get();
|
||||||
var up:Float = inputs[9].get();
|
var up: Float = inputs[9].get();
|
||||||
con.setHingeConstraintLimits(setLimit, low, up);
|
con.setHingeConstraintLimits(setLimit, low, up);
|
||||||
|
|
||||||
case Slider:
|
case Slider:
|
||||||
var setLimit:Bool = inputs[7].get();
|
var setLimit: Bool = inputs[7].get();
|
||||||
var low:Float = inputs[8].get();
|
var low: Float = inputs[8].get();
|
||||||
var up:Float = inputs[9].get();
|
var up: Float = inputs[9].get();
|
||||||
con.setSliderConstraintLimits(setLimit, low, up);
|
con.setSliderConstraintLimits(setLimit, low, up);
|
||||||
|
|
||||||
case Piston:
|
case Piston:
|
||||||
var setLinLimit:Bool = inputs[7].get();
|
var setLinLimit: Bool = inputs[7].get();
|
||||||
var linLow:Float = inputs[8].get();
|
var linLow: Float = inputs[8].get();
|
||||||
var linUp:Float = inputs[9].get();
|
var linUp: Float = inputs[9].get();
|
||||||
var setAngLimit:Bool = inputs[10].get();
|
var setAngLimit: Bool = inputs[10].get();
|
||||||
var angLow:Float = inputs[11].get();
|
var angLow: Float = inputs[11].get();
|
||||||
var angUp:Float = inputs[12].get();
|
var angUp: Float = inputs[12].get();
|
||||||
con.setPistonConstraintLimits(setLinLimit, linLow, linUp, setAngLimit, angLow, angUp);
|
con.setPistonConstraintLimits(setLinLimit, linLow, linUp, setAngLimit, angLow, angUp);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
var spring: Bool = false;
|
var spring: Bool = false;
|
||||||
var prop: PhysicsConstraintNode;
|
var prop: PhysicsConstraintNode;
|
||||||
for(inp in 7...inputs.length)
|
|
||||||
{
|
for (inp in 7...inputs.length) {
|
||||||
prop = inputs[inp].get();
|
prop = inputs[inp].get();
|
||||||
if(prop == null) continue;
|
if (prop == null) continue;
|
||||||
if(prop.isSpring)
|
if (prop.isSpring) {
|
||||||
{
|
|
||||||
spring = true;
|
spring = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(spring) {
|
if (spring) {
|
||||||
con = new PhysicsConstraint(rb1, rb2, GenericSpring, disableCollisions, breakingThreshold);
|
con = new PhysicsConstraint(rb1, rb2, GenericSpring, disableCollisions, breakingThreshold);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
con = new PhysicsConstraint(rb1, rb2, Generic, disableCollisions, breakingThreshold);
|
con = new PhysicsConstraint(rb1, rb2, Generic, disableCollisions, breakingThreshold);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(inp in 7...inputs.length)
|
for (inp in 7...inputs.length) {
|
||||||
{
|
|
||||||
prop = inputs[inp].get();
|
prop = inputs[inp].get();
|
||||||
if(prop == null) continue;
|
if (prop == null) continue;
|
||||||
(inp + ': ');
|
|
||||||
|
|
||||||
if(prop.isSpring)
|
if (prop.isSpring) {
|
||||||
{
|
|
||||||
con.setSpringParams(prop.isSpring, prop.value1, prop.value2, prop.axis, prop.isAngular);
|
con.setSpringParams(prop.isSpring, prop.value1, prop.value2, prop.axis, prop.isAngular);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
con.setGenericConstraintLimits(true, prop.value1, prop.value2, prop.axis, prop.isAngular);
|
con.setGenericConstraintLimits(true, prop.value1, prop.value2, prop.axis, prop.isAngular);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pivotObject.addTrait(con);
|
pivotObject.addTrait(con);
|
||||||
|
|
||||||
}
|
}
|
||||||
#end
|
#end
|
||||||
|
|
||||||
runOutput(0);
|
runOutput(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
package armory.logicnode;
|
package armory.logicnode;
|
||||||
|
|
||||||
|
import iron.object.Object;
|
||||||
|
|
||||||
#if arm_physics
|
#if arm_physics
|
||||||
|
import armory.trait.physics.RigidBody;
|
||||||
import armory.trait.physics.bullet.RigidBody.Shape;
|
import armory.trait.physics.bullet.RigidBody.Shape;
|
||||||
#end
|
#end
|
||||||
import iron.object.Object;
|
|
||||||
import armory.trait.physics.RigidBody;
|
|
||||||
|
|
||||||
class AddRigidBodyNode extends LogicNode {
|
class AddRigidBodyNode extends LogicNode {
|
||||||
|
|
||||||
public var property0: String;//Shape
|
public var property0: String; //Shape
|
||||||
public var property1: Bool;//Advanced
|
public var property1: Bool; //Advanced
|
||||||
public var object: Object;
|
public var object: Object;
|
||||||
|
|
||||||
public function new(tree: LogicTree) {
|
public function new(tree: LogicTree) {
|
||||||
|
@ -18,6 +20,10 @@ class AddRigidBodyNode extends LogicNode {
|
||||||
|
|
||||||
override function run(from: Int) {
|
override function run(from: Int) {
|
||||||
object = inputs[1].get();
|
object = inputs[1].get();
|
||||||
|
if (object == null) return;
|
||||||
|
|
||||||
|
#if arm_physics
|
||||||
|
|
||||||
var mass: Float = inputs[2].get();
|
var mass: Float = inputs[2].get();
|
||||||
var active: Bool = inputs[3].get();
|
var active: Bool = inputs[3].get();
|
||||||
var animated: Bool = inputs[4].get();
|
var animated: Bool = inputs[4].get();
|
||||||
|
@ -50,33 +56,23 @@ class AddRigidBodyNode extends LogicNode {
|
||||||
mask = inputs[17].get();
|
mask = inputs[17].get();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (object == null) return;
|
|
||||||
|
|
||||||
#if arm_physics
|
|
||||||
var rb: RigidBody = object.getTrait(RigidBody);
|
var rb: RigidBody = object.getTrait(RigidBody);
|
||||||
if ((group < 0) || (group > 32)) group = 1; //Limiting max groups to 32
|
if ((group < 0) || (group > 32)) group = 1; //Limiting max groups to 32
|
||||||
if ((mask < 0) || (mask > 32)) mask = 1; //Limiting max masks to 32
|
if ((mask < 0) || (mask > 32)) mask = 1; //Limiting max masks to 32
|
||||||
if (rb == null) {
|
if (rb == null) {
|
||||||
switch (property0){
|
switch (property0) {
|
||||||
case "Box":
|
case "Box": shape = Box;
|
||||||
shape = Box;
|
case "Sphere": shape = Sphere;
|
||||||
case "Sphere":
|
case "Capsule": shape = Capsule;
|
||||||
shape = Sphere;
|
case "Cone": shape = Cone;
|
||||||
case "Capsule":
|
case "Cylinder": shape = Cylinder;
|
||||||
shape = Capsule;
|
case "Convex Hull": shape = ConvexHull;
|
||||||
case "Cone":
|
case "Mesh": shape = Mesh;
|
||||||
shape = Cone;
|
|
||||||
case "Cylinder":
|
|
||||||
shape = Cylinder;
|
|
||||||
case "Convex Hull":
|
|
||||||
shape = ConvexHull;
|
|
||||||
case "Mesh":
|
|
||||||
shape = Mesh;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rb = new RigidBody(shape, mass, friction, bounciness, group, mask);
|
rb = new RigidBody(shape, mass, friction, bounciness, group, mask);
|
||||||
rb.animated = animated;
|
rb.animated = animated;
|
||||||
rb.staticObj = ! active;
|
rb.staticObj = !active;
|
||||||
rb.isTriggerObject(trigger);
|
rb.isTriggerObject(trigger);
|
||||||
|
|
||||||
if (property1) {
|
if (property1) {
|
||||||
|
|
|
@ -9,29 +9,33 @@ class PhysicsConstraintNode extends LogicNode {
|
||||||
public var property0: String; //Linear or Angular
|
public var property0: String; //Linear or Angular
|
||||||
public var property1: String; //Axis
|
public var property1: String; //Axis
|
||||||
public var property2: Bool; //Is a spring
|
public var property2: Bool; //Is a spring
|
||||||
|
|
||||||
|
#if arm_physics
|
||||||
public var value1: Float; //Lower limit or Spring Stiffness
|
public var value1: Float; //Lower limit or Spring Stiffness
|
||||||
public var value2: Float; //Upper limit or Spring Damping
|
public var value2: Float; //Upper limit or Spring Damping
|
||||||
public var isAngular: Bool;
|
public var isAngular: Bool;
|
||||||
public var axis: ConstraintAxis;
|
public var axis: ConstraintAxis;
|
||||||
public var isSpring: Bool;
|
public var isSpring: Bool;
|
||||||
|
#end
|
||||||
|
|
||||||
public function new(tree: LogicTree) {
|
public function new(tree: LogicTree) {
|
||||||
super(tree);
|
super(tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
override function get(from: Int): PhysicsConstraintNode {
|
override function get(from: Int): PhysicsConstraintNode {
|
||||||
|
#if arm_physics
|
||||||
value1 = inputs[0].get();
|
value1 = inputs[0].get();
|
||||||
value2 = inputs[1].get();
|
value2 = inputs[1].get();
|
||||||
|
|
||||||
isAngular = property0 != "Linear";
|
isAngular = property0 != "Linear";
|
||||||
isSpring = property2;
|
isSpring = property2;
|
||||||
|
|
||||||
switch (property1){
|
switch (property1) {
|
||||||
case "X": axis = X;
|
case "X": axis = X;
|
||||||
case "Y": axis = Y;
|
case "Y": axis = Y;
|
||||||
case "Z": axis = Z;
|
case "Z": axis = Z;
|
||||||
}
|
}
|
||||||
|
#end
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue