# Problem drawing simple Lines for a ruler

## Recommended Posts

High,

no idea why BJS struggles with this code:

It fails when I want to push coordinates in my array in this very line:

``myPoints.push(new BABYLON.Vector3(shortLength, currentHeight, 1));``

Here´s the code of my function; doesn't even start in PG:

``````    this.createMeshRuler = function(){

var rulerHeight = 5.000;
var rulerWidth = 0.500;

var sourcePlane = new BABYLON.Plane(0, 0, 0, 0);

sourcePlane.normalize();

var meshRuler = BABYLON.MeshBuilder.CreatePlane("meshRuler", {height:rulerHeight, width: rulerWidth, sourcePlane: sourcePlane, sideOrientation: BABYLON.Mesh.DOUBLESIDE}, this.scene);

meshRuler.position = new BABYLON.Vector3(0.5 * rulerWidth, 0.5 * rulerHeight, 0);

var rulerMaterial = new BABYLON.StandardMaterial("myMaterial", this.scene);

rulerMaterial.emissiveColor = new BABYLON.Color3(1, 1, 0);

meshRuler.material = rulerMaterial;

// Striche einfügen

var restHoehe = rulerHeight;    // verbleibende Höhe bis OK Ruler
var currentHeight = 0;          // aktuelle Höhe beim Aufbauen des Rulers
var step = 0.200;               // Schrittweite
var stepCounter = 0;            // Schrittzähler (Schleifendurchläufe)
var shortLength = 0.2000;
var longLength = 0.3500;

Ende: while (restHoehe > 0) {

currentHeight = restHoehe;

// kurzen Strich
if (stepCounter < 5) {

var myPoints = [];
myPoints.push(new BABYLON.Vector3(0, 0, 0));
myPoints.push(new BABYLON.Vector3(shortLength, currentHeight, 1));

var lines = BABYLON.MeshBuilder.CreateLines("lines", {points: myPoints, updatable: true}, this.scene);
lines.color = new BABYLON.Color3(1, 0, 0);

stepCounter = stepCounter + 1;

currentHeight = currentHeight + step;

// langer Strich
}else if (stepCounter === 5) {

var myPoints = [];
myPoints.push(new BABYLON.Vector3(0, 0, 0));
myPoints.push(new BABYLON.Vector3(longLength, currentHeight, 1));

var lines = BABYLON.MeshBuilder.CreateLines("lines", {points: myPoints, updatable: true}, this.scene);
lines.color = new BABYLON.Color3(1, 0, 0);

stepCounter = 0;

currentHeight = currentHeight + step;

// Error
}else{

}
}
}; ``````

All browsers start to freeze; more or less.

Any suggestions, what´s happening?

BR,

Markus

##### Share on other sites

I would say because restHoehe is never changed so your while(restHoehe > 0) is always true?

##### Share on other sites

@ Pryme8

That´s awesome. Thanks a lot, man, I really appreciate it.

@ Deltakosh

Sounds about right. Damn, I should definitely stop coding after 16 hour.

But for some reason BJS is highly addictive to me.

BR,

Markus

##### Share on other sites

you could also simply use a LineSystem instead :

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.