Jump to content

Canvas2D / Lines2D, update points array?


Numa
 Share

Recommended Posts

Hi there, 

is there a way to dynamically update a Lines2D's points array? I'm trying to have a line drawn between 2 meshes and I want it to stretch if needed when the camera rotates etc so it needs to be updated every frame.

This doesn't seem to work:

var pts = new Array(mesh1, mesh2);
            myLine.points = pts;

The variable is updated but the line isn't redrawn. Is there a flag to trigger a render?

 

Thanks

Link to comment
Share on other sites

11 hours ago, Numa said:

Hi there, 

is there a way to dynamically update a Lines2D's points array? I'm trying to have a line drawn between 2 meshes and I want it to stretch if needed when the camera rotates etc so it needs to be updated every frame.

This doesn't seem to work:


var pts = new Array(mesh1, mesh2);
            myLine.points = pts;

The variable is updated but the line isn't redrawn. Is there a flag to trigger a render?

 

Thanks

Hello, nope, every settings are currently immutable (you set them at construction and can't change them), but it's on my todo list and should be done quickly (especially if you need it). I'm on a short holidays right now away from home, but thursday I'll be back. I'll see what's possible, if I can do it quickly, I keep you in touch.

Link to comment
Share on other sites

  • 9 months later...

I put something into the code to make a line have not been back to that code base for some time. 

Here I found it. 

Let me pseudo code it. 

Every time my position changes or some set interval. 

If I have no points saved (aka no path) 

add the point to TracePath 

Else

If I have one point in TracePath  

add the point to TracePath then

TraceRibbon=BABYLON.Mesh.CreateTube("TraceLine",TracePath,1.0,12,null,0,scene,true, BABYLON.Mesh.BILLBOARDMODE_ALL);

               var mat = new BABYLON.StandardMaterial("TraceRibbonMat", scene);
               mat.alpha = 1.0;
               mat.diffuseColor = new BABYLON.Color3(0.0, 0.0, 1.0);
               mat.backFaceCulling=false;
               TraceRibbon.material=mat;

Else

If I have more than 2 points in TracePath

add new point to TracePath 

then

TraceRibbon=BABYLON.Mesh.CreateTube(null,TracePath,1.0,null,null,null,null,null,null,TraceRibbon); 

 

To KILL it all I make sure the length is > 1

if(TracePath.length>1)
   TraceRibbon.dispose();
TracePath=[];
 

 

 

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...