Skip to content

Commit 382c2cd

Browse files
committed
fixed issue with jsweet function passing
1 parent b4b8fe0 commit 382c2cd

File tree

3 files changed

+81
-64
lines changed

3 files changed

+81
-64
lines changed

src/main/java/org/ssatguru/babylonjs/component/EditControl.java

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import def.babylonjs.babylon.StandardMaterial;
2020
import def.babylonjs.babylon.Vector3;
2121
import jsweet.dom.Event;
22+
import jsweet.dom.EventListener;
2223
import jsweet.dom.HTMLCanvasElement;
2324
import jsweet.dom.PointerEvent;
2425
import jsweet.lang.Array;
@@ -27,7 +28,7 @@
2728
public class EditControl {
2829

2930
private Mesh meshPicked;
30-
HTMLCanvasElement canvas;
31+
private HTMLCanvasElement canvas;
3132
private Scene scene;
3233
private Camera mainCamera;
3334
private Mesh theParent;
@@ -40,6 +41,8 @@ public class EditControl {
4041
private double axesScale = 1;
4142
private StandardMaterial redMat, greenMat, blueMat, whiteMat, yellowMat;
4243
private ActHist actHist;
44+
private Runnable renderer;
45+
private EventListener pointerdown,pointerup,pointermove;
4346

4447
public EditControl(Mesh mesh, Camera camera, HTMLCanvasElement canvas, double scale) {
4548
this.meshPicked = mesh;
@@ -63,13 +66,19 @@ public EditControl(Mesh mesh, Camera camera, HTMLCanvasElement canvas, double sc
6366
this.guideCtl.parent = this.theParent;
6467
createPickPlane();
6568
this.pickPlane.parent = this.theParent;
66-
67-
canvas.addEventListener("pointerdown", this::onPointerDown, false);
68-
canvas.addEventListener("pointerup", this::onPointerUp, false);
69-
canvas.addEventListener("pointermove", this::onPointerMove, false);
69+
70+
71+
this.pointerdown = this::onPointerDown;
72+
this.pointerup = this::onPointerUp;
73+
this.pointermove = this::onPointerMove;
74+
75+
canvas.addEventListener("pointerdown", this.pointerdown, false);
76+
canvas.addEventListener("pointerup", this.pointerup, false);
77+
canvas.addEventListener("pointermove", this.pointermove, false);
78+
7079
setLocalAxes(mesh);
71-
72-
this.scene.registerBeforeRender(this::renderLoopProcess);
80+
this.renderer = this::renderLoopProcess;
81+
this.scene.registerBeforeRender(this.renderer);
7382
}
7483

7584
private void renderLoopProcess() {
@@ -102,12 +111,17 @@ public void redo(){
102111
}
103112

104113
public void detach() {
114+
115+
this.canvas.removeEventListener("pointerdown", this.pointerdown, false);
116+
this.canvas.removeEventListener("pointerup", this.pointerup, false);
117+
this.canvas.removeEventListener("pointermove", this.pointermove, false);
118+
this.scene.unregisterBeforeRender(this.renderer);
119+
disposeAll();
120+
}
121+
122+
public void disposeAll(){
105123
this.theParent.dispose();
106124
this.disposeMaterials();
107-
this.canvas.removeEventListener("pointerdown", this::onPointerDown, false);
108-
this.canvas.removeEventListener("pointerup", this::onPointerUp, false);
109-
this.canvas.removeEventListener("pointermove", this::onPointerMove, false);
110-
this.scene.unregisterBeforeRender(this::renderLoopProcess);
111125
this.actHist = null;
112126
}
113127

@@ -208,13 +222,7 @@ private void onPointerOver() {
208222
this.yaxis.color = Color3.White();
209223
}else if (this.prevOverMesh.name == "Z"){
210224
this.zaxis.color = Color3.White();
211-
}else{
212-
// this.xaxis.color = Color3.White();
213-
// this.yaxis.color = Color3.White();
214-
// this.zaxis.color = Color3.White();
215225
}
216-
217-
218226
}
219227
} else {
220228
if (this.prevOverMesh != null) {
@@ -246,9 +254,6 @@ private void restoreColor(Mesh mesh){
246254
}else{
247255
col = Color3.Yellow();
248256
mat = this.yellowMat;
249-
// this.xaxis.color = Color3.Red();
250-
// this.yaxis.color = Color3.Green();
251-
// this.zaxis.color = Color3.Blue();
252257
}
253258

254259
if (this.rotEnabled){
@@ -380,7 +385,7 @@ private void doTranslation(Vector3 newPos) {
380385
private void doScaling(Vector3 newPos) {
381386

382387
Vector3 ppm = this.prevPos.subtract(this.meshPicked.position);
383-
Vector3 npm = newPos.subtract(this.meshPicked.position);
388+
//Vector3 npm = newPos.subtract(this.meshPicked.position);
384389
Vector3 diff = newPos.subtract(prevPos);
385390
double r = diff.length() / ppm.length();
386391
// double r = diff.length() / 10;
@@ -783,7 +788,8 @@ private void createRotAxes() {
783788
this.rY.isPickable = false;
784789
this.rZ.isPickable = false;
785790

786-
double cl = d, cr = r / 8;
791+
double cl = d;
792+
//cr = r / 8;
787793

788794
rEndX = createCircle(cl / 2);
789795
rEndY = rEndX.clone("");
@@ -801,9 +807,6 @@ private void createRotAxes() {
801807
rEndY.color = Color3.Green();
802808
rEndZ.color = Color3.Blue();
803809

804-
// rEndX.material = this.redMat;
805-
// rEndY.material = this.greenMat;
806-
// rEndZ.material = this.blueMat;
807810

808811
rEndX.renderingGroupId = 1;
809812
rEndY.renderingGroupId = 1;
@@ -1014,7 +1017,7 @@ private static StandardMaterial getStandardMaterial(String name, Color3 col, Sce
10141017
class ActHist{
10151018
private AbstractMesh mesh;
10161019
private int lastMax = 10;
1017-
private Array<Act> acts = new Array();
1020+
private Array<Act> acts = new Array<Act>();
10181021
private int last =-1;
10191022
private int current =-1;
10201023

@@ -1037,17 +1040,18 @@ public void setCapacity(int c){
10371040
lastMax=c-1;
10381041
last=-1;
10391042
current=-1;
1040-
acts = new Array();
1043+
acts = new Array<Act>();
10411044
add();
10421045
}
10431046

10441047
public void add(){
1045-
10461048
Act act = new Act(this.mesh);
10471049
if (current < last){
1048-
for (int i = last;current<last;last--){
1049-
acts.pop();
1050-
}
1050+
acts.splice(current+1);
1051+
last=current;
1052+
// for (int i = last;current<last;last--){
1053+
// acts.pop();
1054+
// }
10511055
}
10521056
if (last == lastMax){
10531057
acts.shift();

webapp/js/org/ssatguru/babylonjs/component/EditControl.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,15 @@ var org;
5151
this.guideCtl.parent = this.theParent;
5252
this.createPickPlane();
5353
this.pickPlane.parent = this.theParent;
54-
canvas.addEventListener("pointerdown", function (evt) { return _this.onPointerDown(evt); }, false);
55-
canvas.addEventListener("pointerup", function (evt) { return _this.onPointerUp(evt); }, false);
56-
canvas.addEventListener("pointermove", function (evt) { return _this.onPointerMove(evt); }, false);
54+
this.pointerdown = function (evt) { return _this.onPointerDown(evt); };
55+
this.pointerup = function (evt) { return _this.onPointerUp(evt); };
56+
this.pointermove = function (evt) { return _this.onPointerMove(evt); };
57+
canvas.addEventListener("pointerdown", this.pointerdown, false);
58+
canvas.addEventListener("pointerup", this.pointerup, false);
59+
canvas.addEventListener("pointermove", this.pointermove, false);
5760
this.setLocalAxes(mesh);
58-
this.scene.registerBeforeRender(function () { return _this.renderLoopProcess(); });
61+
this.renderer = function () { return _this.renderLoopProcess(); };
62+
this.scene.registerBeforeRender(this.renderer);
5963
}
6064
EditControl.prototype.renderLoopProcess = function () {
6165
this.setAxesScale();
@@ -81,13 +85,15 @@ var org;
8185
this.setLocalAxes(this.meshPicked);
8286
};
8387
EditControl.prototype.detach = function () {
84-
var _this = this;
88+
this.canvas.removeEventListener("pointerdown", this.pointerdown, false);
89+
this.canvas.removeEventListener("pointerup", this.pointerup, false);
90+
this.canvas.removeEventListener("pointermove", this.pointermove, false);
91+
this.scene.unregisterBeforeRender(this.renderer);
92+
this.disposeAll();
93+
};
94+
EditControl.prototype.disposeAll = function () {
8595
this.theParent.dispose();
8696
this.disposeMaterials();
87-
this.canvas.removeEventListener("pointerdown", function (evt) { return _this.onPointerDown(evt); }, false);
88-
this.canvas.removeEventListener("pointerup", function (evt) { return _this.onPointerUp(evt); }, false);
89-
this.canvas.removeEventListener("pointermove", function (evt) { return _this.onPointerMove(evt); }, false);
90-
this.scene.unregisterBeforeRender(function () { return _this.renderLoopProcess(); });
9197
this.actHist = null;
9298
};
9399
EditControl.prototype.onPointerDown = function (evt) {
@@ -181,8 +187,6 @@ var org;
181187
else if ((this.prevOverMesh.name == "Z")) {
182188
this.zaxis.color = Color3.White();
183189
}
184-
else {
185-
}
186190
}
187191
}
188192
else {
@@ -319,7 +323,6 @@ var org;
319323
};
320324
EditControl.prototype.doScaling = function (newPos) {
321325
var ppm = this.prevPos.subtract(this.meshPicked.position);
322-
var npm = newPos.subtract(this.meshPicked.position);
323326
var diff = newPos.subtract(this.prevPos);
324327
var r = diff.length() / ppm.length();
325328
if ((this.axisPicked == this.sX)) {
@@ -646,7 +649,6 @@ var org;
646649
this.rY.isPickable = false;
647650
this.rZ.isPickable = false;
648651
var cl = d;
649-
var cr = r / 8;
650652
this.rEndX = this.createCircle(cl / 2);
651653
this.rEndY = this.rEndX.clone("");
652654
this.rEndZ = this.rEndX.clone("");
@@ -854,9 +856,8 @@ var org;
854856
ActHist.prototype.add = function () {
855857
var act = new Act(this.mesh);
856858
if ((this.current < this.last)) {
857-
for (var i = this.last; this.current < this.last; this.last--) {
858-
this.acts.pop();
859-
}
859+
this.acts.splice(this.current + 1);
860+
this.last = this.current;
860861
}
861862
if ((this.last == this.lastMax)) {
862863
this.acts.shift();

webapp/js/org/ssatguru/babylonjs/component/EditControl.ts

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module org.ssatguru.babylonjs.component {
3131
export class EditControl {
3232
private meshPicked: Mesh;
3333

34-
canvas: HTMLCanvasElement;
34+
private canvas: HTMLCanvasElement;
3535

3636
private scene: Scene;
3737

@@ -65,6 +65,14 @@ module org.ssatguru.babylonjs.component {
6565

6666
private actHist: ActHist;
6767

68+
private renderer: () => void;
69+
70+
private pointerdown: EventListener;
71+
72+
private pointerup: EventListener;
73+
74+
private pointermove: EventListener;
75+
6876
public constructor(mesh: Mesh, camera: Camera, canvas: HTMLCanvasElement, scale: number) {
6977
this.meshPicked = mesh;
7078
this.canvas = canvas;
@@ -82,11 +90,15 @@ module org.ssatguru.babylonjs.component {
8290
this.guideCtl.parent = this.theParent;
8391
this.createPickPlane();
8492
this.pickPlane.parent = this.theParent;
85-
canvas.addEventListener("pointerdown", (evt) => { return this.onPointerDown(evt) }, false);
86-
canvas.addEventListener("pointerup", (evt) => { return this.onPointerUp(evt) }, false);
87-
canvas.addEventListener("pointermove", (evt) => { return this.onPointerMove(evt) }, false);
93+
this.pointerdown = (evt) => { return this.onPointerDown(evt) };
94+
this.pointerup = (evt) => { return this.onPointerUp(evt) };
95+
this.pointermove = (evt) => { return this.onPointerMove(evt) };
96+
canvas.addEventListener("pointerdown", this.pointerdown, false);
97+
canvas.addEventListener("pointerup", this.pointerup, false);
98+
canvas.addEventListener("pointermove", this.pointermove, false);
8899
this.setLocalAxes(mesh);
89-
this.scene.registerBeforeRender(() => { return this.renderLoopProcess() });
100+
this.renderer = () => { return this.renderLoopProcess() };
101+
this.scene.registerBeforeRender(this.renderer);
90102
}
91103

92104
private renderLoopProcess() {
@@ -118,12 +130,16 @@ module org.ssatguru.babylonjs.component {
118130
}
119131

120132
public detach() {
133+
this.canvas.removeEventListener("pointerdown", this.pointerdown, false);
134+
this.canvas.removeEventListener("pointerup", this.pointerup, false);
135+
this.canvas.removeEventListener("pointermove", this.pointermove, false);
136+
this.scene.unregisterBeforeRender(this.renderer);
137+
this.disposeAll();
138+
}
139+
140+
public disposeAll() {
121141
this.theParent.dispose();
122142
this.disposeMaterials();
123-
this.canvas.removeEventListener("pointerdown", (evt) => { return this.onPointerDown(evt) }, false);
124-
this.canvas.removeEventListener("pointerup", (evt) => { return this.onPointerUp(evt) }, false);
125-
this.canvas.removeEventListener("pointermove", (evt) => { return this.onPointerMove(evt) }, false);
126-
this.scene.unregisterBeforeRender(() => { return this.renderLoopProcess() });
127143
this.actHist = null;
128144
}
129145

@@ -203,7 +219,6 @@ module org.ssatguru.babylonjs.component {
203219
this.yaxis.color = Color3.White();
204220
} else if((this.prevOverMesh.name == "Z")) {
205221
this.zaxis.color = Color3.White();
206-
} else {
207222
}
208223
}
209224
} else {
@@ -328,7 +343,6 @@ module org.ssatguru.babylonjs.component {
328343

329344
private doScaling(newPos: Vector3) {
330345
var ppm: Vector3 = this.prevPos.subtract(this.meshPicked.position);
331-
var npm: Vector3 = newPos.subtract(this.meshPicked.position);
332346
var diff: Vector3 = newPos.subtract(this.prevPos);
333347
var r: number = diff.length() / ppm.length();
334348
if((this.axisPicked == this.sX)) {
@@ -688,7 +702,6 @@ module org.ssatguru.babylonjs.component {
688702
this.rY.isPickable = false;
689703
this.rZ.isPickable = false;
690704
var cl: number = d;
691-
var cr: number = r / 8;
692705
this.rEndX = this.createCircle(cl / 2);
693706
this.rEndY = this.rEndX.clone("");
694707
this.rEndZ = this.rEndX.clone("");
@@ -902,7 +915,7 @@ module org.ssatguru.babylonjs.component {
902915

903916
private lastMax: number = 10;
904917

905-
private acts: Array<Act> = new Array();
918+
private acts: Array<Act> = new Array<Act>();
906919

907920
private last: number = -1;
908921

@@ -927,16 +940,15 @@ module org.ssatguru.babylonjs.component {
927940
this.lastMax = c - 1;
928941
this.last = -1;
929942
this.current = -1;
930-
this.acts = new Array();
943+
this.acts = new Array<Act>();
931944
this.add();
932945
}
933946

934947
public add() {
935948
var act: Act = new Act(this.mesh);
936949
if((this.current < this.last)) {
937-
for(var i: number = this.last; this.current < this.last; this.last--) {
938-
this.acts.pop();
939-
}
950+
this.acts.splice(this.current + 1);
951+
this.last = this.current;
940952
}
941953
if((this.last == this.lastMax)) {
942954
this.acts.shift();

0 commit comments

Comments
 (0)