Questions about Path3D please help

Hi, I’m Nonso. I’m new to BabylonJS. I’ve been using it for a few weeks now, and I have to say it’s a really amazing engine for webgl stuff, so I decided to use for gamedev. I’m making a weird racing game with an infinite track. I first tried using Path3D dynamically, it didn’t give me what I wanted because it uses a “starting normal” according to the documentation which doesnt look well for the kind of “wierd” racing game I have in mind, as a workaround I generated my own normals and track but I still use path.getTangentAt() for the tangents. I have two questions.

1.) Even though I have this workaround I’m still wondering if it’s possible to set or edit the path’s normals array manually and have it recalculate tangents and binormals. path.getNormals() returns a cloned array.

2.) when I create a new Path once then use path.update(points) in scene.registerBeforeRender or the render loop it throws an error unless I create a new path right before using it which defeats its purpose, I guess I’m doing something wrong. Can I use a curve object instead? but Curve3 doesn’t have the useful getPointAt() like Path3D, could you guide me on how to calculate this like how Path3D does? I already know how to calculate tangents and binormals needed.

If anyone knows what to do here please help. Thanks.

Hello and welcome, let me try to ping some folks for you

@jerome / @JohnK

Hi @TheNosiriN and welcome from me. I have several questions, for example currently I do not know how you are using the normals? As usual everything can be made clearer with if you would produce a (simplified if necessary) playground and an explanation of what you want the objects in the scene to do.

Currently I am making these assumptions.

  1. You know you can set your own normal for the start of the path.
  2. You can have the tangents aligned to the path.
  3. You have read the api Path3D - Babylon.js Documentation
  4. You know you need to make a mesh updatable before you can update it and in the case of rendering lines you can use the instance parameter Create Parametric Shapes - Babylon.js Documentation. However this still does not allow you to update normals of the path.

5 You probably do not know about A Carriage Following a Track - Babylon.js Documentation which may or may not be helpful.

Other than that Path3D is in a sense a theoretical object and as in the snippet of point 5 there is nothing stopping you creating your own object that assigns normals and binormals of your own making at each point on a path.

In answer to

The code (Typescript version) is here Babylon.js/math.path.ts at master · BabylonJS/Babylon.js · GitHub

Please feel free to follow up.

@JohnK thanks for responding, and yes I didn’t know about number 5. I did a bit more research in the documentation and it turns out I can get what I wanted by just using transform nodes and the very useful ExtrudeShapeCustom, I didn’t have to calculate my own stuff or build my own mesh with long messy code. So I wouldn’t have much problems with that.

But still path.update() isn’t working so I quickly made a simplified version of the current methods I’m using: https://playground.babylonjs.com/#7S9AWT#26 see the updatePath() function near the end.

It is to do with changing the number of points, ie update only works if exactly the same number of points are used. You can see this in the PG Babylon.js Playground. Remove a point on line 33 and no errors.

Made a small change around line 215 so that you do not have to dispose and create a new line.

https://playground.babylonjs.com/#7S9AWT#27

Oh I thought it was to replace the actual points array with a new one but it just updates the positions, I think I have an idea on how to use it, when the track reaches max length it will stop creating and start updating. I wanted to abandon the path3d and follow up on that link to make my own getPointAt but I guess I don’t need to anymore. Thanks for your help. I really appreciate it.

The lines updating edit isn’t working but it isn’t important. Thanks anyway.