-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve tracklet visualization with highlights (#42)
* Initial loading of track lineage * Quiet noisy logs * Properly compute track lineage * Update convert_tracks, in particular the comments on time/size * Render a section of the track in a different color; colors follow points rebase to get sub-track coloring, colors follow points * Lint * Set line width in world coords * Remove updating camera target on array change not relevant to this branch, and wasn't working well anyway * Update points geometry allocation to use maxPointsPerTimepoint * Refactor track highlight to use a separate Line2 * Add track length slider * Fix bug where highlights would disappear if tracklets were shorter than the highlight length * API tidying, adding some comments * Refactor so Track is an Object3D * Refactor to clean up and slightly improve performance * Apply suggestions from code review Co-authored-by: Andy Sweet <[email protected]> * Add TrackLine with custom shader, based on Line2 * Use TrackLine instead of combined Line2 visuals * Add some comments, remove unused features from TrackLine * Update src/lib/three/TrackGeometry.ts Co-authored-by: Andy Sweet <[email protected]> * Update src/lib/three/TrackGeometry.ts Co-authored-by: Andy Sweet <[email protected]> * Apply suggestions from code review Co-authored-by: Andy Sweet <[email protected]> * Simplify track fetching/adding based on code review Co-authored-by: Andy Sweet <[email protected]> * Move Track into its own file * Add more comments to modified Line2 code * Don't store LUT texture on Track * Update src/Track.ts Co-authored-by: Andy Sweet <[email protected]> * Refactor to combine Track + TrackLine -> Track --------- Co-authored-by: Andy Sweet <[email protected]>
- Loading branch information
1 parent
865a508
commit 9e6a660
Showing
8 changed files
with
721 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* This class gives a specific type for the Track object, but it's mostly a | ||
* Mesh with a custom initializer. | ||
* | ||
* see: | ||
* https://github.com/mrdoob/three.js/blob/5ed5417d63e4eeba5087437cc27ab1e3d0813aea/examples/jsm/lines/Line2.js | ||
* https://github.com/mrdoob/three.js/blob/5ed5417d63e4eeba5087437cc27ab1e3d0813aea/examples/jsm/lines/LineSegments2.js | ||
*/ | ||
import { Mesh } from "three"; | ||
|
||
import { TrackGeometry } from "./TrackGeometry.js"; | ||
import { TrackMaterial } from "./TrackMaterial.js"; | ||
|
||
export class Track extends Mesh { | ||
isTrack = true; | ||
type = "Track"; | ||
declare geometry: TrackGeometry; | ||
declare material: TrackMaterial; | ||
|
||
static new(positions: Float32Array, pointIDs: Int32Array, maxPointsPerTimepoint: number) { | ||
const geometry = new TrackGeometry(); | ||
const material = new TrackMaterial({ | ||
vertexColors: true, | ||
trackwidth: 0.3, | ||
highlightwidth: 2.0, | ||
showtrack: true, | ||
transparent: true, | ||
opacity: 0.5, | ||
}); | ||
const track = new Track(geometry, material); | ||
|
||
const time: number[] = []; | ||
const pos = Array.from(positions); | ||
const colors: number[] = []; | ||
const n = pos.length / 3; | ||
for (const [i, id] of pointIDs.entries()) { | ||
const t = Math.floor(id / maxPointsPerTimepoint); | ||
time.push(t); | ||
// TODO: use a LUT for the main track, too | ||
colors.push(((0.9 * (n - i)) / n) ** 3, ((0.9 * (n - i)) / n) ** 3, (0.9 * (n - i)) / n); | ||
} | ||
track.geometry.setPositions(pos); | ||
track.geometry.setColors(colors); | ||
track.geometry.setTime(time); | ||
track.geometry.computeBoundingSphere(); | ||
return track; | ||
} | ||
|
||
updateHighlightLine(minTime: number, maxTime: number) { | ||
this.material.minTime = minTime; | ||
this.material.maxTime = maxTime; | ||
this.material.needsUpdate = true; | ||
} | ||
|
||
dispose() { | ||
this.geometry.dispose(); | ||
this.material.dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* This class maintains the geometry of the track, adding instanced attributes for time. | ||
* see: | ||
* https://github.com/mrdoob/three.js/blob/dev/examples/jsm/lines/LineGeometry.js | ||
*/ | ||
import { InstancedInterleavedBuffer, InterleavedBufferAttribute } from "three"; | ||
import { LineSegmentsGeometry } from "three/examples/jsm/Addons.js"; | ||
|
||
class TrackGeometry extends LineSegmentsGeometry { | ||
isTrackGeometry = true; | ||
type = "TrackGeometry"; | ||
|
||
setPositions(array: number[] | Float32Array) { | ||
// converts [ x1, y1, z1, x2, y2, z2, ... ] to pairs format | ||
|
||
const length = array.length - 3; | ||
const points = new Float32Array(2 * length); | ||
|
||
for (let i = 0; i < length; i += 3) { | ||
points[2 * i] = array[i]; | ||
points[2 * i + 1] = array[i + 1]; | ||
points[2 * i + 2] = array[i + 2]; | ||
|
||
points[2 * i + 3] = array[i + 3]; | ||
points[2 * i + 4] = array[i + 4]; | ||
points[2 * i + 5] = array[i + 5]; | ||
} | ||
|
||
super.setPositions(points); | ||
|
||
return this; | ||
} | ||
|
||
setColors(array: number[] | Float32Array) { | ||
// converts [ r1, g1, b1, r2, g2, b2, ... ] to pairs format | ||
|
||
const length = array.length - 3; | ||
const colors = new Float32Array(2 * length); | ||
|
||
for (let i = 0; i < length; i += 3) { | ||
colors[2 * i] = array[i]; | ||
colors[2 * i + 1] = array[i + 1]; | ||
colors[2 * i + 2] = array[i + 2]; | ||
|
||
colors[2 * i + 3] = array[i + 3]; | ||
colors[2 * i + 4] = array[i + 4]; | ||
colors[2 * i + 5] = array[i + 5]; | ||
} | ||
|
||
super.setColors(colors); | ||
|
||
return this; | ||
} | ||
|
||
setTime(array: number[]) { | ||
// TRACK SPECIFIC CODE ADDED | ||
// converts [ t1, t2, ... ] to pairs format | ||
// this ecodes the timepoint of each point in the track | ||
// this can be used in shaders to highlight specific segments in the | ||
// track based on time | ||
|
||
// float32 should be sufficient given we're expecting ~1000 timepoints | ||
const length = array.length - 1; | ||
const times = new Float32Array(2 * length); | ||
|
||
for (let i = 0; i < length; i++) { | ||
times[2 * i] = array[i]; | ||
times[2 * i + 1] = array[i + 1]; | ||
} | ||
|
||
const time = new InstancedInterleavedBuffer(times, 2, 1); | ||
this.setAttribute("instanceTimeStart", new InterleavedBufferAttribute(time, 1, 0)); | ||
this.setAttribute("instanceTimeEnd", new InterleavedBufferAttribute(time, 1, 1)); | ||
|
||
return this; | ||
} | ||
} | ||
|
||
export { TrackGeometry }; |
Oops, something went wrong.