Jump to content

Problem drawing simple Lines for a ruler


Topper
 Share

Recommended Posts

High,

no idea why BJS struggles with this code:

https://www.babylonjs-playground.com/##RCZLX7

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{

                /// Alert

            }
        }
    }; 

All browsers start to freeze; more or less.

Any suggestions, what´s happening?

BR,

Markus

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...