The online racing simulator
Drawing LFS tracks using pth files and d3.js (& pth's converted to json)
Good afternoon chaps,

This winter holiday season I've been playing a bit of LFS and fiddling with nodejs and insim (another project). As part of making that project useful I've also been playing with d3.js, which can be used to draw and manipulate svg data.

The basic premise of this afternoon was that I wanted to draw a rough interpretation of a LFS track. The link below is the fruits of my work.

https://github.com/theangryangel/LFS-.pth---d3.js

I'm using it in conjunction with the nodejs insim client I'm fiddling with to produce a basic ajax based live tracker. Figured someone else might have a use for it as well.

If you do intend on using it, please be aware that I've not included d3.min.js (available from http://mbostock.github.com/d3/) and there are a couple of caveats, most notably:
  • Track doesn't match the same orientation as LFS - could be acheived reasonably easily using a transform
  • Doesn't take into account the actual track width - only uses the center coordinates
Despite these draw backs, I think it's good enough for my purposes, and hopefully good enough if anyone else wants to use it.

I've included my own converted pth files, and the implementation I used to convert them. The converted pth files are at 1/6th the "resolution" of the originals as I found that there were just too many data points.

Example image of what it looks out, out of the box, attached.
Attached images
example.png
Hey Karl, good to see your still fiddling with LFS.

How you been?
Quote from mcgas001 :Hey Karl, good to see your still fiddling with LFS.

Blame the lack of work over the winter holiday and wanting to shut myself away from the world First time I've even touched LFS since I got rid of the wheel a few years ago really. Glad to see the forums haven't changed from their normal bitchy nature

Quote from mcgas001 :How you been?

Not bad, nowt interesting since we last spoke. Just lots of work and a mostly other non-LFS side projects here and there

How are you? Well?
I wonder if we can use the HTML5's File-API and JavaScript Typed Arrays to read the data directly from the PTH file.

PTH VERSION 0 - Path files for Live for Speed S2
=============


The nodes are given by a fixed point position (X, Y, Z) and a
floating point direction (X, Y, Z)

The node can be considered as a line perpendicular to its direction.

Outer and driving area left and right limits are given.


TYPES :
=======

1) X,Y,Z int : 32-bit fixed point world coordinates (1 metre = 65536)

X and Y are ground coordinates, Z is up.

2) float : 32 bit floating point number


FILE DESCRIPTION :
==================

num unit offset description
--- ---- ------ -----------

HEADER BLOCK :

6 char 0 LFSPTH : do not read file if no match
1 byte 6 version : 0 - do not read file if > 0
1 byte 7 revision : 0 - do not read file if > 0
1 int 8 num nodes : number
1 int 12 finish line : number
......NODE BLOCKS


NODE BLOCK :

1 int 0 centre X : fp
1 int 4 centre Y : fp
1 int 8 centre Z : fp
1 float 12 dir X : float
1 float 16 dir Y : float
1 float 20 dir Z : float
1 float 24 limit left : outer limit
1 float 28 limit right : outer limit
1 float 32 drive left : road limit
1 float 36 drive right : road limit

Actually this reminds me that i just finished a project that maybe the devs could use for a new track, it has terrain and everything......

should post some files for them.
Quote from Dygear :I wonder if we can use the HTML5's File-API and JavaScript Typed Arrays to read the data directly from the PTH file.

Should be feasible, but impractical given that not all browsers support either very well/at all.

The main problem I had with using a full pth file (after translation to json) was the sheer number of nodes caused the browser to go mental for a while. I will admit I didn't bother investigating whether that was down to d3 translating the points, or if it was parsing the JSON or something else. I just cut down the number of nodes and moved on to more interesting things.

Given how few live trackers there seem to be outside of LFS remote, which is flash based, I figured it may be useful to someone else. Think I actually spent more time writing the comments cogently, than anything else tbh.

If anyone wants to play further I'm not gonna stop them, but it's done what I wanted at the time and I'm probably not going to do much more on this until I've finished playing with the "other (related) project" - if at all
Quote from the_angry_angel :Blame the lack of work over the winter holiday and wanting to shut myself away from the world First time I've even touched LFS since I got rid of the wheel a few years ago really. Glad to see the forums haven't changed from their normal bitchy nature

Not bad, nowt interesting since we last spoke. Just lots of work and a mostly other non-LFS side projects here and there

How are you? Well?

Haha, I'm the same mate. Not played propley in god knows how long! Yes, I did notice that, Same old, same old .

Good good mate. Yeh, im good thanks, Just getting on with life as usuall.

FGED GREDG RDFGDR GSFDG