Use tabs for Haxe.

This commit is contained in:
Lubos Lenco 2016-10-15 20:19:09 +02:00
parent dec9eb1351
commit 361b1d91cb
19 changed files with 475 additions and 541 deletions

View file

@ -3,6 +3,7 @@ package armory.object;
import iron.Scene;
import iron.math.Vec4;
// Structure for setting shader uniforms
class Uniforms {
public static function register() {

View file

@ -2,6 +2,7 @@ package armory.renderpath;
import iron.data.RenderPath;
// Fast Fourier transform data
class FFT {
static var firstFrame = true;

View file

@ -8,150 +8,135 @@ import iron.data.RenderPath;
import iron.data.WorldData;
class HosekWilkieRadianceData {
static inline var PI = 3.1415926535;
public var A = new FastVector3();
public var B = new FastVector3();
public var C = new FastVector3();
public var D = new FastVector3();
public var E = new FastVector3();
public var F = new FastVector3();
public var G = new FastVector3();
public var H = new FastVector3();
public var I = new FastVector3();
public var Z = new FastVector3();
// public var floats:haxe.ds.Vector<Float>;
public var A = new FastVector3();
public var B = new FastVector3();
public var C = new FastVector3();
public var D = new FastVector3();
public var E = new FastVector3();
public var F = new FastVector3();
public var G = new FastVector3();
public var H = new FastVector3();
public var I = new FastVector3();
public var Z = new FastVector3();
function evaluateSpline(spline:Array<Float>, index:Int, stride:Int, value:Float):Float {
return
1 * Math.pow(1 - value, 5) * spline[index + 0 * stride] +
5 * Math.pow(1 - value, 4) * Math.pow(value, 1) * spline[index + 1 * stride] +
10 * Math.pow(1 - value, 3) * Math.pow(value, 2) * spline[index + 2 * stride] +
10 * Math.pow(1 - value, 2) * Math.pow(value, 3) * spline[index + 3 * stride] +
5 * Math.pow(1 - value, 1) * Math.pow(value, 4) * spline[index + 4 * stride] +
1 * Math.pow(value, 5) * spline[index + 5 * stride];
}
function clamp(n:Int, lower:Int, upper:Int) {
return n <= lower ? lower : n >= upper ? upper : n;
}
function clampF(n:Float, lower:Float, upper:Float) {
return n <= lower ? lower : n >= upper ? upper : n;
}
function evaluate(dataset:Array<Float>, index:Int, stride:Int, turbidity:Float, albedo:Float, sunTheta:Float):Float {
// Splines are functions of elevation^1/3
var elevationK:Float = Math.pow(Math.max(0.0, 1.0 - sunTheta / (PI / 2.0)), 1.0 / 3.0);
// Table has values for turbidity 1..10
var turbidity0:Int = clamp(Std.int(turbidity), 1, 10);
var turbidity1:Int = Std.int(Math.min(turbidity0 + 1, 10));
var turbidityK:Float = clampF(turbidity - turbidity0, 0.0, 1.0);
var datasetA0Index = index;
var datasetA1Index = index + stride * 6 * 10;
var a0t0:Float = evaluateSpline(dataset, datasetA0Index + stride * 6 * (turbidity0 - 1), stride, elevationK);
var a1t0:Float = evaluateSpline(dataset, datasetA1Index + stride * 6 * (turbidity0 - 1), stride, elevationK);
var a0t1:Float = evaluateSpline(dataset, datasetA0Index + stride * 6 * (turbidity1 - 1), stride, elevationK);
var a1t1:Float = evaluateSpline(dataset, datasetA1Index + stride * 6 * (turbidity1 - 1), stride, elevationK);
return a0t0 * (1 - albedo) * (1 - turbidityK) + a1t0 * albedo * (1 - turbidityK) + a0t1 * (1 - albedo) * turbidityK + a1t1 * albedo * turbidityK;
}
function hosek_wilkie(cos_theta:Float, gamma:Float, cos_gamma:Float, A:FastVector3, B:FastVector3, C:FastVector3, D:FastVector3, E:FastVector3, F:FastVector3, G:FastVector3, H:FastVector3, I:FastVector3):FastVector3 {
var val = (1.0 + cos_gamma * cos_gamma);
var chix = val / Math.pow(1.0 + H.x * H.x - 2.0 * cos_gamma * H.x, 1.5);
var chiy = val / Math.pow(1.0 + H.y * H.y - 2.0 * cos_gamma * H.y, 1.5);
var chiz = val / Math.pow(1.0 + H.z * H.z - 2.0 * cos_gamma * H.z, 1.5);
var chi = new FastVector3(chix, chiy, chiz);
var vx = (1.0 + A.x * Math.exp(B.x / (cos_theta + 0.01))) * (C.x + D.x * Math.exp(E.x * gamma) + F.x * (cos_gamma * cos_gamma) + G.x * chi.x + I.x * Math.sqrt(Math.max(0.0, cos_theta)));
var vy = (1.0 + A.y * Math.exp(B.y / (cos_theta + 0.01))) * (C.y + D.y * Math.exp(E.y * gamma) + F.y * (cos_gamma * cos_gamma) + G.y * chi.y + I.y * Math.sqrt(Math.max(0.0, cos_theta)));
var vz = (1.0 + A.z * Math.exp(B.z / (cos_theta + 0.01))) * (C.z + D.z * Math.exp(E.z * gamma) + F.z * (cos_gamma * cos_gamma) + G.z * chi.z + I.z * Math.sqrt(Math.max(0.0, cos_theta)));
return new FastVector3(vx, vy, vz);
}
function setVector(v:FastVector3, index:Int, f:Float) {
index == 0 ? v.x = f : index == 1 ? v.y = f : v.z = f;
}
public function new(sunTheta:Float, turbidity:Float, albedo:Float, normalizedSunY:Float) {
for (i in 0...3) {
setVector(A, i, evaluate(HosekWilkieData.datasetsRGB[i], 0, 9, turbidity, albedo, sunTheta));
setVector(B, i, evaluate(HosekWilkieData.datasetsRGB[i], 1, 9, turbidity, albedo, sunTheta));
setVector(C, i, evaluate(HosekWilkieData.datasetsRGB[i], 2, 9, turbidity, albedo, sunTheta));
setVector(D, i, evaluate(HosekWilkieData.datasetsRGB[i], 3, 9, turbidity, albedo, sunTheta));
setVector(E, i, evaluate(HosekWilkieData.datasetsRGB[i], 4, 9, turbidity, albedo, sunTheta));
setVector(F, i, evaluate(HosekWilkieData.datasetsRGB[i], 5, 9, turbidity, albedo, sunTheta));
setVector(G, i, evaluate(HosekWilkieData.datasetsRGB[i], 6, 9, turbidity, albedo, sunTheta));
// Swapped in the dataset
setVector(H, i, evaluate(HosekWilkieData.datasetsRGB[i], 8, 9, turbidity, albedo, sunTheta));
setVector(I, i, evaluate(HosekWilkieData.datasetsRGB[i], 7, 9, turbidity, albedo, sunTheta));
setVector(Z, i, evaluate(HosekWilkieData.datasetsRGBRad[i], 0, 1, turbidity, albedo, sunTheta));
}
if (normalizedSunY != 0.0) {
var S:FastVector3 = hosek_wilkie(Math.cos(sunTheta), 0, 1.0, A, B, C, D, E, F, G, H, I);
S.x *= Z.x;
S.y *= Z.y;
S.z *= Z.z;
var dotS = S.dot(new FastVector3(0.2126, 0.7152, 0.0722));
Z.x /= dotS;
Z.y /= dotS;
Z.z /= dotS;
Z = Z.mult(normalizedSunY);
}
// Store in a single float array for shader access
// floats = new haxe.ds.Vector([]);
}
function evaluateSpline(spline:Array<Float>, index:Int, stride:Int, value:Float):Float {
return
1 * Math.pow(1 - value, 5) * spline[index + 0 * stride] +
5 * Math.pow(1 - value, 4) * Math.pow(value, 1) * spline[index + 1 * stride] +
10 * Math.pow(1 - value, 3) * Math.pow(value, 2) * spline[index + 2 * stride] +
10 * Math.pow(1 - value, 2) * Math.pow(value, 3) * spline[index + 3 * stride] +
5 * Math.pow(1 - value, 1) * Math.pow(value, 4) * spline[index + 4 * stride] +
1 * Math.pow(value, 5) * spline[index + 5 * stride];
}
function clamp(n:Int, lower:Int, upper:Int) {
return n <= lower ? lower : n >= upper ? upper : n;
}
function clampF(n:Float, lower:Float, upper:Float) {
return n <= lower ? lower : n >= upper ? upper : n;
}
function evaluate(dataset:Array<Float>, index:Int, stride:Int, turbidity:Float, albedo:Float, sunTheta:Float):Float {
// Splines are functions of elevation^1/3
var elevationK:Float = Math.pow(Math.max(0.0, 1.0 - sunTheta / (Math.PI / 2.0)), 1.0 / 3.0);
// Table has values for turbidity 1..10
var turbidity0:Int = clamp(Std.int(turbidity), 1, 10);
var turbidity1:Int = Std.int(Math.min(turbidity0 + 1, 10));
var turbidityK:Float = clampF(turbidity - turbidity0, 0.0, 1.0);
var datasetA0Index = index;
var datasetA1Index = index + stride * 6 * 10;
var a0t0:Float = evaluateSpline(dataset, datasetA0Index + stride * 6 * (turbidity0 - 1), stride, elevationK);
var a1t0:Float = evaluateSpline(dataset, datasetA1Index + stride * 6 * (turbidity0 - 1), stride, elevationK);
var a0t1:Float = evaluateSpline(dataset, datasetA0Index + stride * 6 * (turbidity1 - 1), stride, elevationK);
var a1t1:Float = evaluateSpline(dataset, datasetA1Index + stride * 6 * (turbidity1 - 1), stride, elevationK);
return a0t0 * (1 - albedo) * (1 - turbidityK) + a1t0 * albedo * (1 - turbidityK) + a0t1 * (1 - albedo) * turbidityK + a1t1 * albedo * turbidityK;
}
function hosek_wilkie(cos_theta:Float, gamma:Float, cos_gamma:Float, A:FastVector3, B:FastVector3, C:FastVector3, D:FastVector3, E:FastVector3, F:FastVector3, G:FastVector3, H:FastVector3, I:FastVector3):FastVector3 {
var val = (1.0 + cos_gamma * cos_gamma);
var chix = val / Math.pow(1.0 + H.x * H.x - 2.0 * cos_gamma * H.x, 1.5);
var chiy = val / Math.pow(1.0 + H.y * H.y - 2.0 * cos_gamma * H.y, 1.5);
var chiz = val / Math.pow(1.0 + H.z * H.z - 2.0 * cos_gamma * H.z, 1.5);
var chi = new FastVector3(chix, chiy, chiz);
var vx = (1.0 + A.x * Math.exp(B.x / (cos_theta + 0.01))) * (C.x + D.x * Math.exp(E.x * gamma) + F.x * (cos_gamma * cos_gamma) + G.x * chi.x + I.x * Math.sqrt(Math.max(0.0, cos_theta)));
var vy = (1.0 + A.y * Math.exp(B.y / (cos_theta + 0.01))) * (C.y + D.y * Math.exp(E.y * gamma) + F.y * (cos_gamma * cos_gamma) + G.y * chi.y + I.y * Math.sqrt(Math.max(0.0, cos_theta)));
var vz = (1.0 + A.z * Math.exp(B.z / (cos_theta + 0.01))) * (C.z + D.z * Math.exp(E.z * gamma) + F.z * (cos_gamma * cos_gamma) + G.z * chi.z + I.z * Math.sqrt(Math.max(0.0, cos_theta)));
return new FastVector3(vx, vy, vz);
}
function setVector(v:FastVector3, index:Int, f:Float) {
index == 0 ? v.x = f : index == 1 ? v.y = f : v.z = f;
}
public function new(sunTheta:Float, turbidity:Float, albedo:Float, normalizedSunY:Float) {
for (i in 0...3) {
setVector(A, i, evaluate(HosekWilkieData.datasetsRGB[i], 0, 9, turbidity, albedo, sunTheta));
setVector(B, i, evaluate(HosekWilkieData.datasetsRGB[i], 1, 9, turbidity, albedo, sunTheta));
setVector(C, i, evaluate(HosekWilkieData.datasetsRGB[i], 2, 9, turbidity, albedo, sunTheta));
setVector(D, i, evaluate(HosekWilkieData.datasetsRGB[i], 3, 9, turbidity, albedo, sunTheta));
setVector(E, i, evaluate(HosekWilkieData.datasetsRGB[i], 4, 9, turbidity, albedo, sunTheta));
setVector(F, i, evaluate(HosekWilkieData.datasetsRGB[i], 5, 9, turbidity, albedo, sunTheta));
setVector(G, i, evaluate(HosekWilkieData.datasetsRGB[i], 6, 9, turbidity, albedo, sunTheta));
// Swapped in the dataset
setVector(H, i, evaluate(HosekWilkieData.datasetsRGB[i], 8, 9, turbidity, albedo, sunTheta));
setVector(I, i, evaluate(HosekWilkieData.datasetsRGB[i], 7, 9, turbidity, albedo, sunTheta));
setVector(Z, i, evaluate(HosekWilkieData.datasetsRGBRad[i], 0, 1, turbidity, albedo, sunTheta));
}
if (normalizedSunY != 0.0) {
var S:FastVector3 = hosek_wilkie(Math.cos(sunTheta), 0, 1.0, A, B, C, D, E, F, G, H, I);
S.x *= Z.x;
S.y *= Z.y;
S.z *= Z.z;
var dotS = S.dot(new FastVector3(0.2126, 0.7152, 0.0722));
Z.x /= dotS;
Z.y /= dotS;
Z.z /= dotS;
Z = Z.mult(normalizedSunY);
}
}
}
class HosekWilkie {
static var firstFrame = true;
public static var data:HosekWilkieRadianceData = null;
public static var sunDirection:FastVector3;
static var firstFrame = true;
public static var data:HosekWilkieRadianceData = null;
public static var sunDirection:FastVector3;
public static function recompute(sunPositionX:Float, turbidity:Float, albedo:Float, normalizedSunY:Float) {
data = new HosekWilkieRadianceData(sunPositionX, turbidity, albedo, normalizedSunY);
}
public static function recompute(sunPositionX:Float, turbidity:Float, albedo:Float, normalizedSunY:Float) {
data = new HosekWilkieRadianceData(sunPositionX, turbidity, albedo, normalizedSunY);
}
public static function init(world:WorldData) {
var probe = world.getGlobalProbe();
var dir = probe.raw.sun_direction;
sunDirection = new FastVector3(dir[0], dir[1], dir[2]);
public static function init(world:WorldData) {
var probe = world.getGlobalProbe();
var dir = probe.raw.sun_direction;
sunDirection = new FastVector3(dir[0], dir[1], dir[2]);
// Extract direction from lamp
// var mat = iron.data.Data.getMaterial("World_material", "World_material").data;
// var lamp = iron.Scene.active.lamps[0];
// var ltr = lamp.transform;
// var lf = ltr.matrix.look2();
// lamp.data.data.strength = 3.3 - Math.abs(ltr.absy()) / 45;
// probe.strength = 1.2 - Math.abs(ltr.absy()) / 45;
// mat.contexts[0].bind_constants[0].float = probe.strength + 0.5;
// mat.contexts[0].bind_constants[1].vec3[0] = lf.x;
// mat.contexts[0].bind_constants[1].vec3[1] = lf.y;
// mat.contexts[0].bind_constants[1].vec3[2] = lf.z;
// sunDirection = new FastVector3(lf.x, lf.y, lf.z);
//
// Extract direction from lamp
// var mat = iron.data.Data.getMaterial("World_material", "World_material").data;
// var lamp = iron.Scene.active.lamps[0];
// var ltr = lamp.transform;
// var lf = ltr.matrix.look2();
// lamp.data.data.strength = 3.3 - Math.abs(ltr.absy()) / 45;
// probe.strength = 1.2 - Math.abs(ltr.absy()) / 45;
// mat.contexts[0].bind_constants[0].float = probe.strength + 0.5;
// mat.contexts[0].bind_constants[1].vec3[0] = lf.x;
// mat.contexts[0].bind_constants[1].vec3[1] = lf.y;
// mat.contexts[0].bind_constants[1].vec3[2] = lf.z;
// sunDirection = new FastVector3(lf.x, lf.y, lf.z);
var sunPositionX = Math.acos(sunDirection.z);
var turbidity = probe.raw.turbidity;
var albedo = probe.raw.ground_albedo;
HosekWilkie.recompute(sunPositionX, turbidity, albedo, 1.15);
}
// public static function getData(world:WorldData):haxe.ds.Vector<Float> {
// if (HosekWilkie.data == null) HosekWilkie.init(world);
// return HosekWilkie.data.floats;
// }
public static function run(path:RenderPath) {
// Set uniforms
}
var sunPositionX = Math.acos(sunDirection.z);
var turbidity = probe.raw.turbidity;
var albedo = probe.raw.ground_albedo;
HosekWilkie.recompute(sunPositionX, turbidity, albedo, 1.15);
}
}

View file

@ -21,7 +21,7 @@ class ArcBall extends Trait {
if (Input.touch) {
object.transform.rotate(new Vec4(0, 0, 1), -Input.deltaX / 100);
object.transform.buildMatrix();
object.transform.rotate(object.transform.matrix._right2(), -Input.deltaY / 100);
object.transform.rotate(object.transform.matrix._right(), -Input.deltaY / 100);
object.transform.buildMatrix();
}
}

View file

@ -6,19 +6,19 @@ import iron.object.MeshObject;
@:keep
class MirrorTexture extends Trait {
var cameraName:String;
var cameraName:String;
public function new(cameraName:String) {
super();
public function new(cameraName:String) {
super();
this.cameraName = cameraName;
notifyOnInit(init);
}
this.cameraName = cameraName;
notifyOnInit(init);
}
function init() {
function init() {
var image = iron.Scene.active.getCamera(cameraName).data.mirror;
var o = cast(object, iron.object.MeshObject);
o.materials[0].contexts[0].textures[0] = image; // Override diffuse texture
}
}
}

View file

@ -5,27 +5,27 @@ import iron.Trait;
@:keep
class NavAgent extends Trait {
// nav mesh
// target object
// behaviour
// nav mesh
// target object
// behaviour
public function new() {
super();
public function new() {
super();
notifyOnInit(init);
notifyOnUpdate(update);
notifyOnInit(init);
notifyOnUpdate(update);
notifyOnRemove(removed);
}
}
function removed() {
}
function init() {
function init() {
}
}
function update() {
function update() {
}
}
}

View file

@ -5,23 +5,23 @@ import iron.Trait;
@:keep
class NavCrowd extends Trait {
public function new() {
super();
public function new() {
super();
notifyOnInit(init);
notifyOnUpdate(update);
notifyOnInit(init);
notifyOnUpdate(update);
notifyOnRemove(removed);
}
}
function removed() {
}
function init() {
function init() {
}
}
function update() {
function update() {
}
}
}

View file

@ -5,23 +5,23 @@ import iron.Trait;
@:keep
class NavMesh extends Trait {
public function new() {
super();
public function new() {
super();
notifyOnInit(init);
notifyOnUpdate(update);
notifyOnInit(init);
notifyOnUpdate(update);
notifyOnRemove(removed);
}
}
function removed() {
}
function init() {
function init() {
}
}
function update() {
function update() {
}
}
}

View file

@ -61,49 +61,49 @@ class PhysicsDrag extends Trait {
// localPivotVec.applyMat4(inv);
// var localPivot:BtVector3 = BtVector3.create(localPivotVec.x, localPivotVec.y, localPivotVec.z);
var ct = b.body.ptr.getCenterOfMassTransform();
var inv = ct.inverse();
var ct = b.body.ptr.getCenterOfMassTransform();
var inv = ct.inverse();
#if js
var localPivot:BtVector3 = inv.mulVec(pickPos);
var localPivot:BtVector3 = inv.mulVec(pickPos);
#elseif cpp
var localPivot:BtVector3 = untyped __cpp__("inv.value * pickPos.value"); // Operator overload
#end
var localPivot:BtVector3 = untyped __cpp__("inv.value * pickPos.value"); // Operator overload
#end
var tr = BtTransform.create();
tr.value.setIdentity();
tr.value.setOrigin(localPivot);
var tr = BtTransform.create();
tr.value.setIdentity();
tr.value.setOrigin(localPivot);
pickConstraint = BtGeneric6DofConstraint.create(b.body.value, tr.value, false);
pickConstraint = BtGeneric6DofConstraint.create(b.body.value, tr.value, false);
pickConstraint.value.setLinearLowerLimit(BtVector3.create(0, 0, 0).value);
pickConstraint.value.setLinearUpperLimit(BtVector3.create(0, 0, 0).value);
pickConstraint.value.setAngularLowerLimit(BtVector3.create(-10, -10, -10).value);
pickConstraint.value.setAngularUpperLimit(BtVector3.create(10, 10, 10).value);
pickConstraint.value.setLinearUpperLimit(BtVector3.create(0, 0, 0).value);
pickConstraint.value.setAngularLowerLimit(BtVector3.create(-10, -10, -10).value);
pickConstraint.value.setAngularUpperLimit(BtVector3.create(10, 10, 10).value);
physics.world.ptr.addConstraint(pickConstraint, false);
physics.world.ptr.addConstraint(pickConstraint, false);
/*pickConstraint.value.setParam(4, 0.8, 0);
pickConstraint.value.setParam(4, 0.8, 1);
pickConstraint.value.setParam(4, 0.8, 2);
pickConstraint.value.setParam(4, 0.8, 3);
pickConstraint.value.setParam(4, 0.8, 4);
pickConstraint.value.setParam(4, 0.8, 5);
/*pickConstraint.value.setParam(4, 0.8, 0);
pickConstraint.value.setParam(4, 0.8, 1);
pickConstraint.value.setParam(4, 0.8, 2);
pickConstraint.value.setParam(4, 0.8, 3);
pickConstraint.value.setParam(4, 0.8, 4);
pickConstraint.value.setParam(4, 0.8, 5);
pickConstraint.value.setParam(1, 0.1, 0);
pickConstraint.value.setParam(1, 0.1, 1);
pickConstraint.value.setParam(1, 0.1, 2);
pickConstraint.value.setParam(1, 0.1, 3);
pickConstraint.value.setParam(1, 0.1, 4);
pickConstraint.value.setParam(1, 0.1, 5);*/
pickConstraint.value.setParam(1, 0.1, 0);
pickConstraint.value.setParam(1, 0.1, 1);
pickConstraint.value.setParam(1, 0.1, 2);
pickConstraint.value.setParam(1, 0.1, 3);
pickConstraint.value.setParam(1, 0.1, 4);
pickConstraint.value.setParam(1, 0.1, 5);*/
var v = BtVector3.create(pickPos.x() - rayFrom.value.x(),
pickPos.y() - rayFrom.value.y(),
pickPos.z() - rayFrom.value.z());
var v = BtVector3.create(pickPos.x() - rayFrom.value.x(),
pickPos.y() - rayFrom.value.y(),
pickPos.z() - rayFrom.value.z());
pickDist = v.value.length();
pickDist = v.value.length();
Input.occupied = true;
Input.occupied = true;
}
}
@ -113,40 +113,40 @@ class PhysicsDrag extends Trait {
physics.world.ptr.removeConstraint(pickConstraint);
pickConstraint = null;
pickedBody = null;
}
}
Input.occupied = false;
Input.occupied = false;
}
else if (Input.touch) {
if (pickConstraint != null) {
if (pickConstraint != null) {
setRays();
setRays();
// Keep it at the same picking distance
var btRayTo = BtVector3.create(rayTo.value.x(), rayTo.value.y(), rayTo.value.z());
var btRayFrom = BtVector3.create(rayFrom.value.x(), rayFrom.value.y(), rayFrom.value.z());
// Keep it at the same picking distance
var btRayTo = BtVector3.create(rayTo.value.x(), rayTo.value.y(), rayTo.value.z());
var btRayFrom = BtVector3.create(rayFrom.value.x(), rayFrom.value.y(), rayFrom.value.z());
var dir = BtVector3.create(btRayTo.value.x() - btRayFrom.value.x(),
btRayTo.value.y() - btRayFrom.value.y(),
btRayTo.value.z() - btRayFrom.value.z());
var dir = BtVector3.create(btRayTo.value.x() - btRayFrom.value.x(),
btRayTo.value.y() - btRayFrom.value.y(),
btRayTo.value.z() - btRayFrom.value.z());
var bt = dir.value.normalize();
bt.setX(bt.x() * pickDist);
bt.setY(bt.y() * pickDist);
bt.setZ(bt.z() * pickDist);
var bt = dir.value.normalize();
bt.setX(bt.x() * pickDist);
bt.setY(bt.y() * pickDist);
bt.setZ(bt.z() * pickDist);
var newPivotB = BtVector3.create(btRayFrom.value.x() + bt.x(),
btRayFrom.value.y() + bt.y(),
btRayFrom.value.z() + bt.z());
var newPivotB = BtVector3.create(btRayFrom.value.x() + bt.x(),
btRayFrom.value.y() + bt.y(),
btRayFrom.value.z() + bt.z());
#if js
pickConstraint.value.getFrameOffsetA().setOrigin(newPivotB.value);
pickConstraint.value.getFrameOffsetA().setOrigin(newPivotB.value);
#elseif cpp
pickConstraint.value.setFrameOffsetAOrigin(newPivotB.value);
pickConstraint.value.setFrameOffsetAOrigin(newPivotB.value);
#end
}
}
}
}

View file

@ -17,6 +17,12 @@ class CameraController extends Trait {
var body:RigidBody;
var camera:CameraObject;
var moveForward = false;
var moveBackward = false;
var moveLeft = false;
var moveRight = false;
var jump = false;
public function new() {
super();
@ -31,11 +37,6 @@ class CameraController extends Trait {
kha.input.Keyboard.get().notify(onDown, onUp);
}
var moveForward = false;
var moveBackward = false;
var moveLeft = false;
var moveRight = false;
var jump = false;
function onDown(key: kha.Key, char: String) {
if (char == Keymap.forward) moveForward = true;
else if (char == Keymap.right) moveRight = true;

View file

@ -13,124 +13,124 @@ import zui.Id;
class Console extends Trait {
#if (!arm_profile)
public function new() { super(); }
public function new() { super(); }
#else
var ui:Zui;
var path:RenderPath;
var ui:Zui;
var path:RenderPath;
var lastTime = 0.0;
var frameTime = 0.0;
var totalTime = 0.0;
var frames = 0;
var lastTime = 0.0;
var frameTime = 0.0;
var totalTime = 0.0;
var frames = 0;
var frameTimeAvg = 0.0;
var frameTimeAvgMin = 0.0;
var frameTimeAvgMax = 0.0;
var renderTime = 0.0;
var renderTimeAvg = 0.0;
var updateTime = 0.0;
var updateTimeAvg = 0.0;
var physTime = 0.0;
var physTimeAvg = 0.0;
var frameTimeAvg = 0.0;
var frameTimeAvgMin = 0.0;
var frameTimeAvgMax = 0.0;
var renderTime = 0.0;
var renderTimeAvg = 0.0;
var updateTime = 0.0;
var updateTimeAvg = 0.0;
var physTime = 0.0;
var physTimeAvg = 0.0;
public function new() {
super();
public function new() {
super();
iron.data.Data.getFont('droid_sans.ttf', function(font:kha.Font) {
ui = new Zui(font, 17, 16, 0, 1.0, 2.0);
notifyOnInit(init);
notifyOnRender2D(render2D);
notifyOnUpdate(update);
});
}
iron.data.Data.getFont('droid_sans.ttf', function(font:kha.Font) {
ui = new Zui(font, 17, 16, 0, 1.0, 2.0);
notifyOnInit(init);
notifyOnRender2D(render2D);
notifyOnUpdate(update);
});
}
function init() {
path = cast(object, CameraObject).renderPath;
}
function init() {
path = cast(object, CameraObject).renderPath;
}
function render2D(g:kha.graphics2.Graphics) {
g.end();
ui.begin(g);
if (ui.window(Id.window(), 0, 0, 185, iron.App.h())) {
if (ui.node(Id.node(), "Profile (ms)", 0, true)) {
var avg = Math.round(frameTimeAvg * 10000) / 10;
var avgMin = Math.round(frameTimeAvgMin * 10000) / 10;
var avgMax = Math.round(frameTimeAvgMax * 10000) / 10;
ui.text('frame: $avg ($avgMin/$avgMax)');
var gpuTime = frameTimeAvg - renderTimeAvg - updateTimeAvg;
if (gpuTime < renderTimeAvg) gpuTime = renderTimeAvg;
ui.text("gpu: " + Math.round(gpuTime * 10000) / 10);
ui.text("render: " + Math.round(renderTimeAvg * 10000) / 10);
ui.text("update: " + Math.round(updateTimeAvg * 10000) / 10);
ui.indent();
ui.text("phys: " + Math.round(physTimeAvg * 10000) / 10);
ui.text("anim: 0.0");
ui.unindent();
}
ui.separator();
if (ui.node(Id.node(), "Render Path", 0, false)) {
ui.text("draw calls: " + RenderPath.drawCalls);
ui.text("render targets: " + path.data.pathdata.raw.render_targets.length);
for (i in 0...path.passNames.length) {
path.passEnabled[i] = ui.check(Id.nest(Id.check(), i), path.passNames[i], path.passEnabled[i]);
}
}
ui.separator();
if (ui.node(Id.node(), "Inspector", 0, false)) {
function drawList(id:String, objs:Array<iron.object.Object>) {
for (i in 0...objs.length) {
var o = objs[i];
o.visible = ui.check(Id.nest(id, i), o.name + " (" + Std.int(o.transform.absx() * 100) / 100 + ", " + Std.int(o.transform.absy() * 100) / 100 + ", " + Std.int(o.transform.absz() * 100) / 100 + ")", o.visible);
}
}
function render2D(g:kha.graphics2.Graphics) {
g.end();
ui.begin(g);
if (ui.window(Id.window(), 0, 0, 185, iron.App.h())) {
if (ui.node(Id.node(), "Profile (ms)", 0, true)) {
var avg = Math.round(frameTimeAvg * 10000) / 10;
var avgMin = Math.round(frameTimeAvgMin * 10000) / 10;
var avgMax = Math.round(frameTimeAvgMax * 10000) / 10;
ui.text('frame: $avg ($avgMin/$avgMax)');
var gpuTime = frameTimeAvg - renderTimeAvg - updateTimeAvg;
if (gpuTime < renderTimeAvg) gpuTime = renderTimeAvg;
ui.text("gpu: " + Math.round(gpuTime * 10000) / 10);
ui.text("render: " + Math.round(renderTimeAvg * 10000) / 10);
ui.text("update: " + Math.round(updateTimeAvg * 10000) / 10);
ui.indent();
ui.text("phys: " + Math.round(physTimeAvg * 10000) / 10);
ui.text("anim: 0.0");
ui.unindent();
}
ui.separator();
if (ui.node(Id.node(), "Render Path", 0, false)) {
ui.text("draw calls: " + RenderPath.drawCalls);
ui.text("render targets: " + path.data.pathdata.raw.render_targets.length);
for (i in 0...path.passNames.length) {
path.passEnabled[i] = ui.check(Id.nest(Id.check(), i), path.passNames[i], path.passEnabled[i]);
}
}
ui.separator();
if (ui.node(Id.node(), "Inspector", 0, false)) {
function drawList(id:String, objs:Array<iron.object.Object>) {
for (i in 0...objs.length) {
var o = objs[i];
o.visible = ui.check(Id.nest(id, i), o.name + " (" + Std.int(o.transform.absx() * 100) / 100 + ", " + Std.int(o.transform.absy() * 100) / 100 + ", " + Std.int(o.transform.absz() * 100) / 100 + ")", o.visible);
}
}
drawList(Id.check(), cast iron.Scene.active.meshes);
drawList(Id.check(), cast iron.Scene.active.lamps);
drawList(Id.check(), cast iron.Scene.active.cameras);
drawList(Id.check(), cast iron.Scene.active.speakers);
}
}
ui.end();
drawList(Id.check(), cast iron.Scene.active.meshes);
drawList(Id.check(), cast iron.Scene.active.lamps);
drawList(Id.check(), cast iron.Scene.active.cameras);
drawList(Id.check(), cast iron.Scene.active.speakers);
}
}
ui.end();
g.begin(false);
g.begin(false);
#if arm_profile
totalTime += frameTime;
renderTime += iron.App.renderTime;
frames++;
if (totalTime > 1.0) {
var t = totalTime / frames;
// Second frame
if (frameTimeAvg > 0) {
if (t < frameTimeAvgMin || frameTimeAvgMin == 0) frameTimeAvgMin = t;
if (t > frameTimeAvgMax || frameTimeAvgMax == 0) frameTimeAvgMax = t;
}
totalTime += frameTime;
renderTime += iron.App.renderTime;
frames++;
if (totalTime > 1.0) {
var t = totalTime / frames;
// Second frame
if (frameTimeAvg > 0) {
if (t < frameTimeAvgMin || frameTimeAvgMin == 0) frameTimeAvgMin = t;
if (t > frameTimeAvgMax || frameTimeAvgMax == 0) frameTimeAvgMax = t;
}
frameTimeAvg = t;
renderTimeAvg = renderTime / frames;
updateTimeAvg = updateTime / frames;
physTimeAvg = physTime / frames;
totalTime = 0;
renderTime = 0;
updateTime = 0;
physTime = 0;
frames = 0;
}
frameTime = Scheduler.realTime() - lastTime;
lastTime = Scheduler.realTime();
frameTimeAvg = t;
renderTimeAvg = renderTime / frames;
updateTimeAvg = updateTime / frames;
physTimeAvg = physTime / frames;
totalTime = 0;
renderTime = 0;
updateTime = 0;
physTime = 0;
frames = 0;
}
frameTime = Scheduler.realTime() - lastTime;
lastTime = Scheduler.realTime();
#end
}
}
function update() {
function update() {
#if arm_profile
updateTime += iron.App.updateTime;
#if arm_physics
physTime += PhysicsWorld.physTime;
#end
updateTime += iron.App.updateTime;
#if arm_physics
physTime += PhysicsWorld.physTime;
#end
#end
}
}
#end
}

View file

@ -9,94 +9,94 @@ import iron.math.RayCaster;
@:keep
class EditorSpace extends Trait {
var gizmo:Object;
var arrowX:Object;
var arrowY:Object;
var arrowZ:Object;
var selected:Transform = null;
var gizmo:Object;
var arrowX:Object;
var arrowY:Object;
var arrowZ:Object;
var selected:Transform = null;
var moveX = false;
var moveY = false;
var moveZ = false;
var moveX = false;
var moveY = false;
var moveZ = false;
static var first = true;
static var first = true;
public function new() {
super();
notifyOnInit(init);
}
public function new() {
super();
notifyOnInit(init);
}
function init() {
// gizmo = iron.Scene.active.getChild('ArrowGizmo');
// arrowX = iron.Scene.active.getChild('ArrowX');
// arrowY = iron.Scene.active.getChild('ArrowY');
// arrowZ = iron.Scene.active.getChild('ArrowZ');
function init() {
// gizmo = iron.Scene.active.getChild('ArrowGizmo');
// arrowX = iron.Scene.active.getChild('ArrowX');
// arrowY = iron.Scene.active.getChild('ArrowY');
// arrowZ = iron.Scene.active.getChild('ArrowZ');
notifyOnUpdate(update);
notifyOnUpdate(update);
if (first) {
first = false;
kha.input.Keyboard.get().notify(onKeyDown, onKeyUp);
}
}
if (first) {
first = false;
kha.input.Keyboard.get().notify(onKeyDown, onKeyUp);
}
}
function onKeyDown(key: kha.Key, char: String) {
if (char == 'Z' || key == kha.Key.ESC) trace('__arm|quit');
}
function onKeyDown(key: kha.Key, char: String) {
if (char == 'Z' || key == kha.Key.ESC) trace('__arm|quit');
}
function onKeyUp(key: kha.Key, char: String) {
}
function onKeyUp(key: kha.Key, char: String) {
}
function update() {
function update() {
if (Input.started2) {
var transforms:Array<Transform> = [];
for (o in iron.Scene.active.meshes) transforms.push(o.transform);
var hit = RayCaster.getClosestBoxIntersect(transforms, Input.x, Input.y, iron.Scene.active.camera);
if (hit != null) {
var loc = hit.loc;
// gizmo.transform.loc.set(loc.x, loc.y, loc.z);
// gizmo.transform.buildMatrix();
selected = hit;
trace('__arm|select|' + selected.object.name);
}
}
if (Input.started2) {
var transforms:Array<Transform> = [];
for (o in iron.Scene.active.meshes) transforms.push(o.transform);
var hit = RayCaster.getClosestBoxIntersect(transforms, Input.x, Input.y, iron.Scene.active.camera);
if (hit != null) {
var loc = hit.loc;
// gizmo.transform.loc.set(loc.x, loc.y, loc.z);
// gizmo.transform.buildMatrix();
selected = hit;
trace('__arm|select|' + selected.object.name);
}
}
if (selected != null) {
if (Input.started) {
if (selected != null) {
if (Input.started) {
var transforms = [arrowX.transform, arrowY.transform, arrowZ.transform];
var transforms = [arrowX.transform, arrowY.transform, arrowZ.transform];
var hit = RayCaster.getClosestBoxIntersect(transforms, Input.x, Input.y, iron.Scene.active.camera);
if (hit != null) {
if (hit.object.name == 'ArrowX') moveX = true;
else if (hit.object.name == 'ArrowY') moveY = true;
else if (hit.object.name == 'ArrowX') moveZ = true;
}
}
var hit = RayCaster.getClosestBoxIntersect(transforms, Input.x, Input.y, iron.Scene.active.camera);
if (hit != null) {
if (hit.object.name == 'ArrowX') moveX = true;
else if (hit.object.name == 'ArrowY') moveY = true;
else if (hit.object.name == 'ArrowX') moveZ = true;
}
}
if (moveX || moveY || moveZ) {
Input.occupied = true;
if (moveX || moveY || moveZ) {
Input.occupied = true;
if (moveX) selected.loc.x += Input.deltaX / 110.0;
if (moveY) selected.loc.y += Input.deltaX / 110.0;
if (moveZ) selected.loc.z += Input.deltaX / 110.0;
selected.buildMatrix();
if (moveX) selected.loc.x += Input.deltaX / 110.0;
if (moveY) selected.loc.y += Input.deltaX / 110.0;
if (moveZ) selected.loc.z += Input.deltaX / 110.0;
selected.buildMatrix();
// gizmo.transform.loc.set(selected.loc.x, selected.loc.y, selected.loc.z);
// gizmo.transform.buildMatrix();
}
}
// gizmo.transform.loc.set(selected.loc.x, selected.loc.y, selected.loc.z);
// gizmo.transform.buildMatrix();
}
}
if (Input.released) {
Input.occupied = false;
// Move operator creator into separate class..
// Map directly to bl operators - setx to translate
if (moveX) trace('__arm|setx|' + selected.object.name + '|' + selected.loc.x);
moveX = moveY = moveZ = false;
}
}
if (Input.released) {
Input.occupied = false;
// Move operator creator into separate class..
// Map directly to bl operators - setx to translate
if (moveX) trace('__arm|setx|' + selected.object.name + '|' + selected.loc.x);
moveX = moveY = moveZ = false;
}
}
}

View file

@ -7,25 +7,15 @@ class JSScript extends Trait {
static var api:JSScriptAPI = null;
#if cpp
// static var ctx:haxeduktape.DukContext = null;
#end
public function new(scriptBlob:String) {
super();
public function new(scriptBlob:String) {
super();
iron.data.Data.getBlob(scriptBlob + '.js', function(blob:kha.Blob) {
var src = blob.toString();
iron.data.Data.getBlob(scriptBlob + '.js', function(blob:kha.Blob) {
var src = blob.toString();
#if js
if (api == null) api = new JSScriptAPI();
untyped __js__("eval(src);");
#else
// if (ctx == null) {
// ctx = new haxeduktape.DukContext();
// api = new JSScriptAPI(ctx);
// }
// ctx.evalString(src);
untyped __js__("eval(src);");
#end
});
}
});
}
}

View file

@ -2,45 +2,8 @@ package armory.trait.internal;
#if cpp
// import haxeduktape.Duktape;
// @:headerCode('
// #include <duktape.h>
// ')
@:keep
class JSScriptAPI {
/*
static var ctx:haxeduktape.DukContext;
static function console_log(rawctx:cpp.RawPointer<Duk_context>):Int {
var arg = ctx.requireNumber(0);
trace(arg);
// ctx.pushNumber(arg * arg);
return 1;
}
public function new(_ctx:haxeduktape.DukContext) {
ctx = _ctx;
var rawctx = ctx.ctx;
// Console
ctx.pushGlobalObject();
ctx.pushObject();
untyped __cpp__('
const duk_function_list_entry console_module_funcs[] = {
{ "log", console_log, 1 },
{ NULL, NULL, 0 }
}');
untyped __cpp__("duk_put_function_list(rawctx, -1, console_module_funcs)");
ctx.putPropString("console");
ctx.pop();
}
*/
}
class JSScriptAPI { }
#else

View file

@ -29,30 +29,30 @@ class MovieTexture extends Trait {
}
}
public function new(videoName:String) {
super();
public function new(videoName:String) {
super();
this.videoName = videoName;
if (!created) {
created = true;
notifyOnInit(init);
notifyOnRender2D(render);
notifyOnInit(init);
notifyOnRender2D(render);
}
}
}
function init() {
function init() {
iron.data.Data.getVideo(videoName, function(vid:kha.Video) {
video = vid;
iron.data.Data.getVideo(videoName, function(vid:kha.Video) {
video = vid;
video.play(true);
image = Image.createRenderTarget(getPower2(video.width()), getPower2(video.height()));
var o = cast(object, iron.object.MeshObject);
o.materials[0].contexts[0].textures[0] = image; // Override diffuse texture
});
}
});
}
function render(g:kha.graphics2.Graphics) {
if (video == null) return;

View file

@ -5,34 +5,34 @@ import iron.Trait;
@:keep
class NodeExecutor extends Trait {
var baseNode:armory.logicnode.Node;
var nodeInits:Array<Void->Void> = [];
var nodeUpdates:Array<Void->Void> = [];
var baseNode:armory.logicnode.Node;
var nodeInits:Array<Void->Void> = [];
var nodeUpdates:Array<Void->Void> = [];
public function new() {
super();
public function new() {
super();
notifyOnUpdate(update);
}
notifyOnUpdate(update);
}
public function start(baseNode:armory.logicnode.Node) {
this.baseNode = baseNode;
baseNode.start(this);
}
public function start(baseNode:armory.logicnode.Node) {
this.baseNode = baseNode;
baseNode.start(this);
}
function update() {
if (nodeInits.length > 0) {
for (f in nodeInits) { if (nodeInits.length == 0) break; f(); f = null; }
nodeInits.splice(0, nodeInits.length);
}
for (f in nodeUpdates) f();
}
function update() {
if (nodeInits.length > 0) {
for (f in nodeInits) { if (nodeInits.length == 0) break; f(); f = null; }
nodeInits.splice(0, nodeInits.length);
}
for (f in nodeUpdates) f();
}
public function notifyOnNodeInit(f:Void->Void) {
nodeInits.push(f);
}
public function notifyOnNodeInit(f:Void->Void) {
nodeInits.push(f);
}
public function notifyOnNodeUpdate(f:Void->Void) {
nodeUpdates.push(f);
}
public function notifyOnNodeUpdate(f:Void->Void) {
nodeUpdates.push(f);
}
}

View file

@ -162,7 +162,7 @@ class PathTracer extends Trait {
mvp.multmat2(camera.P);
var inverse = Mat4.identity();
// jitter.multmat2(mvp);
inverse.inverse2(mvp);
// inverse.getInverse(mvp);
var matrix = inverse;
// Set uniforms

View file

@ -157,53 +157,53 @@ class PhysicsWorld extends Trait {
break; // TODO: only one contact point for now
}
}
}
}
}
public var rayCallback:ClosestRayResultCallbackPointer;
public function pickClosest(inputX:Float, inputY:Float):RigidBody {
var rayFrom = getRayFrom();
var rayTo = getRayTo(inputX, inputY);
var rayFrom = getRayFrom();
var rayTo = getRayTo(inputX, inputY);
rayCallback = ClosestRayResultCallback.create(rayFrom.value, rayTo.value);
world.ptr.rayTest(rayFrom.value, rayTo.value, rayCallback.value);
if (rayCallback.value.hasHit()) {
#if js
var co = rayCallback.value.get_m_collisionObject();
rayCallback = ClosestRayResultCallback.create(rayFrom.value, rayTo.value);
world.ptr.rayTest(rayFrom.value, rayTo.value, rayCallback.value);
if (rayCallback.value.hasHit()) {
#if js
var co = rayCallback.value.get_m_collisionObject();
var body = untyped Ammo.btRigidBody.prototype.upcast(co);
return rbMap.get(untyped body.userIndex);
#elseif cpp
var co = rayCallback.value.m_collisionObject;
return rbMap.get(co.value.getUserIndex());
#end
}
else {
return null;
}
}
return rbMap.get(untyped body.userIndex);
#elseif cpp
var co = rayCallback.value.m_collisionObject;
return rbMap.get(co.value.getUserIndex());
#end
}
else {
return null;
}
}
public function getRayFrom():BtVector3Pointer {
var camera = iron.Scene.active.camera;
return BtVector3.create(camera.transform.absx(), camera.transform.absy(), camera.transform.absz());
}
public function getRayFrom():BtVector3Pointer {
var camera = iron.Scene.active.camera;
return BtVector3.create(camera.transform.absx(), camera.transform.absy(), camera.transform.absz());
}
public function getRayTo(inputX:Float, inputY:Float):BtVector3Pointer {
var camera = iron.Scene.active.camera;
var start = new Vec4();
var end = new Vec4();
RayCaster.getDirection(start, end, inputX, inputY, camera);
return BtVector3.create(end.x, end.y, end.z);
}
public function getRayTo(inputX:Float, inputY:Float):BtVector3Pointer {
var camera = iron.Scene.active.camera;
var start = new Vec4();
var end = new Vec4();
RayCaster.getDirection(start, end, inputX, inputY, camera);
return BtVector3.create(end.x, end.y, end.z);
}
public function notifyOnPreUpdate(f:Void->Void) {
if (preUpdates == null) preUpdates = [];
preUpdates.push(f);
}
public function notifyOnPreUpdate(f:Void->Void) {
if (preUpdates == null) preUpdates = [];
preUpdates.push(f);
}
public function removePreUpdate(f:Void->Void) {
preUpdates.remove(f);
}
public function removePreUpdate(f:Void->Void) {
preUpdates.remove(f);
}
#end
}

View file

@ -35,13 +35,6 @@ project.addSources('Sources');
if dce_full:
f.write("project.addParameter('-dce full');")
# Electron live patching
# if is_play and wrd.ArmPlayLivePatch == True and wrd.ArmPlayRuntime == 'Electron':
# f.write("project.addDefine('arm_patch_electron');\n")
# Native scripting
# f.write(add_armory_library(sdk_path + '/lib/', 'haxeduktape'))
for ref in shader_references:
f.write("project.addShaders('" + ref + "');\n")