Clone traits

This commit is contained in:
luboslenco
2020-02-03 18:11:20 +01:00
parent 8790ca7420
commit 9d9267cbd1
4 changed files with 20 additions and 16 deletions
-5
View File
@@ -115,7 +115,6 @@ class ImportMesh {
var ar = path.split("/");
var s = ar[ar.length - 1];
object.name = s.substring(0, s.length - 4);
// md.geom.calculateAABB();
// var aabb = md.geom.aabb;
// var dim = new TFloat32Array(3);
@@ -123,10 +122,6 @@ class ImportMesh {
// dim[1] = aabb.y;
// dim[2] = aabb.z;
// object.raw.dimensions = dim;
#if arm_physics
object.addTrait(new arm.plugin.PhysicsBody());
#end
Context.selectObject(object);
}
else { // Replace
+4 -7
View File
@@ -54,9 +54,10 @@ class Gizmo {
object.transform.buildMatrix();
#if arm_physics
object.addTrait(new arm.plugin.PhysicsBody());
#end
for (t in mo.traits) { // Clone traits
var trait = Type.createInstance(Type.getClass(t), []);
object.addTrait(trait);
}
Context.selectObject(object);
}
@@ -70,10 +71,6 @@ class Gizmo {
object.transform.scale.setFrom(lo.transform.scale);
object.transform.buildMatrix();
#if arm_physics
object.addTrait(new arm.plugin.PhysicsBody());
#end
Context.selectObject(object);
}
Context.rdirty = 3;
+14 -1
View File
@@ -14,7 +14,20 @@ class PhysicsBody extends iron.Trait {
@:keep
public var props = ["mass"];
public var mass = 1.0;
public var mass(default, set) = 0.0;
@:keep
function set_mass(f: Float): Float {
if (ready) {
remove();
var t = new PhysicsBody();
t.mass = f;
object.addTrait(t);
}
else mass = f;
return f;
}
public var friction = 0.5;
public var restitution = 0.0;
public var collisionMargin = 0.0;
+2 -3
View File
@@ -18,7 +18,6 @@ class TabTraits {
ui.row([1 / 4]);
if (ui.button("New")) {
UIMenu.draw(function(ui:Zui) {
ui.fill(0, 0, ui._w / ui.SCALE(), ui.t.ELEMENT_H * traits.length, ui.t.SEPARATOR_COL);
ui.text("New", Right, ui.t.HIGHLIGHT_COL);
for (t in traits) {
if (ui.button(t, Left)) {
@@ -28,7 +27,7 @@ class TabTraits {
Context.object.addTrait(inst);
}
}
});
}, traits.length);
}
if (Context.object.traits.length > 0) {
@@ -38,7 +37,7 @@ class TabTraits {
var id = Id.handle();
id.value = Reflect.field(t, untyped t.props[i]);
ui.slider(id, untyped t.props[i]);
Reflect.setField(t, untyped t.props[i], id.value);
if (id.changed) Reflect.setProperty(t, untyped t.props[i], id.value);
}
}
}