Implemented vessel sprite display.

This commit is contained in:
Krafpy
2022-07-17 10:08:30 +02:00
parent 3258cb098d
commit 7178bc2778
6 changed files with 121 additions and 1 deletions

View File

@@ -65,4 +65,5 @@ workers:
trajectoryDraw:
samplePoints: 2500 # number sample points for each tarjectory arc draw
spritesSize: 0.08 # size of the sprites for maneuvers, encounters, escapes
spritesSize: 0.08 # size of the sprites for maneuvers, encounters, escapes
podSpriteSize: 0.06 # size of the pod sprite

View File

@@ -134,6 +134,7 @@ export function initEditor(controls, system, config, canvas) {
if (trajectory) {
trajectory.remove();
}
systemTime.input(updateSystemTime);
};
const displayFoundTrajectory = () => {
trajectory = new Trajectory(solver.bestSteps, system, config);
@@ -142,6 +143,11 @@ export function initEditor(controls, system, config, canvas) {
detailsSelector.select(0);
detailsSelector.enable();
stepSlider.enable();
systemTime.input(() => {
updateSystemTime();
trajectory.updatePodPosition(systemTime);
});
trajectory.updatePodPosition(systemTime);
console.log(solver.bestDeltaV);
};
const findTrajectory = async () => {

View File

@@ -8,6 +8,7 @@ export class Trajectory {
this.config = config;
this._orbitObjects = [];
this._spriteObjects = [];
this._podSpriteIndex = 0;
this.orbits = [];
this._maneuvres = [];
this._flybys = [];
@@ -32,6 +33,7 @@ export class Trajectory {
textureLoader.load("sprites/encounter.png", loaded("encounter"));
textureLoader.load("sprites/escape.png", loaded("escape"));
textureLoader.load("sprites/maneuver.png", loaded("maneuver"));
textureLoader.load("sprites/pod.png", loaded("pod"));
}
draw(resolution) {
const numSteps = this.steps.length;
@@ -129,6 +131,14 @@ export class Trajectory {
};
const id = this.system.addCustomUpdate(updateSpritesDisplay);
this._spritesUpdateFunId = id;
const { podSpriteSize } = this.config.trajectoryDraw;
const podSpriteMat = Trajectory.sprites.get("pod");
podSpriteMat.depthTest = false;
const podSprite = createSprite(podSpriteMat, 0xFFFFFF, false, podSpriteSize);
const group = this.system.objectsOfBody(this.steps[0].attractorId);
group.add(podSprite);
this._podSpriteIndex = 0;
this._spriteObjects[this._podSpriteIndex].push(podSprite);
}
_calculateManeuvresDetails() {
const departureDate = this.steps[0].dateOfStart;
@@ -180,6 +190,7 @@ export class Trajectory {
controls.centerOnTarget();
systemTime.time.dateSeconds = date;
systemTime.update();
this.updatePodPosition(systemTime);
};
resultItems.depDateSpan.onclick = onDateClick(depDate.dateSeconds);
const { stepSlider } = resultItems;
@@ -278,6 +289,41 @@ export class Trajectory {
this._displayedSteps[i] = visible;
}
}
updatePodPosition(systemTime) {
const lastStep = this.steps[this.steps.length - 1];
const missionStart = this.steps[0].dateOfStart;
const missionEnd = lastStep.dateOfStart + lastStep.duration;
let date = systemTime.dateSeconds;
if (date < missionStart)
date = missionStart;
else if (date > missionEnd)
date = missionEnd;
let i = 1;
for (; i < this.steps.length - 1; i++) {
const { dateOfStart, duration } = this.steps[i];
if (date >= dateOfStart && date < dateOfStart + duration)
break;
}
i = Math.min(i, this.steps.length - 2);
const step = this.steps[i];
const pod = this._spriteObjects[this._podSpriteIndex].pop();
const curAttrId = this.steps[this._podSpriteIndex].attractorId;
const curGroup = this.system.objectsOfBody(curAttrId);
curGroup.remove(pod);
this._spriteObjects[i].push(pod);
this._podSpriteIndex = i;
const newAttrId = step.attractorId;
const newGroup = this.system.objectsOfBody(newAttrId);
newGroup.add(pod);
const orbit = this.orbits[i];
const relDate = date - step.dateOfStart;
const { startM } = step;
const trueAnom = orbit.solveTrueAnomalyAtDate(startM, relDate);
const pos = orbit.positionFromTrueAnomaly(trueAnom);
const { scale } = this.config.rendering;
pod.position.set(pos.x, pos.y, pos.z);
pod.position.multiplyScalar(scale);
}
get _totalDeltaV() {
let total = 0;
for (const details of this._maneuvres) {

View File

@@ -183,6 +183,7 @@ export function initEditor(controls: CameraController, system: SolarSystem, conf
if(trajectory){
trajectory.remove();
}
systemTime.input(updateSystemTime);
}
const displayFoundTrajectory = () => {
@@ -194,6 +195,13 @@ export function initEditor(controls: CameraController, system: SolarSystem, conf
detailsSelector.enable();
stepSlider.enable();
systemTime.input(() => {
updateSystemTime();
//@ts-ignore
trajectory.updatePodPosition(systemTime);
});
trajectory.updatePodPosition(systemTime);
console.log(solver.bestDeltaV);
};

View File

@@ -12,6 +12,7 @@ export class Trajectory {
private _orbitObjects: THREE.Object3D[] = [];
private _spriteObjects: THREE.Sprite[][] = [];
private _podSpriteIndex: number = 0;
public readonly orbits: Orbit[] = [];
@@ -46,6 +47,7 @@ export class Trajectory {
textureLoader.load("sprites/encounter.png", loaded("encounter"));
textureLoader.load("sprites/escape.png", loaded("escape"));
textureLoader.load("sprites/maneuver.png", loaded("maneuver"));
textureLoader.load("sprites/pod.png", loaded("pod"));
}
/**
@@ -183,6 +185,17 @@ export class Trajectory {
// function which is called once each frame.
const id = this.system.addCustomUpdate(updateSpritesDisplay);
this._spritesUpdateFunId = id;
// Create pod sprite
const {podSpriteSize} = this.config.trajectoryDraw;
const podSpriteMat = <THREE.SpriteMaterial>Trajectory.sprites.get("pod");
podSpriteMat.depthTest = false;
const podSprite = createSprite(podSpriteMat, 0xFFFFFF, false, podSpriteSize);
const group = this.system.objectsOfBody(this.steps[0].attractorId);
group.add(podSprite);
this._podSpriteIndex = 0;
this._spriteObjects[this._podSpriteIndex].push(podSprite);
}
/**
@@ -266,6 +279,7 @@ export class Trajectory {
controls.centerOnTarget();
systemTime.time.dateSeconds = date;
systemTime.update();
this.updatePodPosition(systemTime);
};
// set the system time to the departure date time when the span is clicked
resultItems.depDateSpan.onclick = onDateClick(depDate.dateSeconds);
@@ -397,6 +411,50 @@ export class Trajectory {
}
}
public updatePodPosition(systemTime: TimeSelector){
const lastStep = this.steps[this.steps.length-1];
const missionStart = this.steps[0].dateOfStart;
const missionEnd = lastStep.dateOfStart + lastStep.duration;
let date = systemTime.dateSeconds;
if(date < missionStart) date = missionStart;
else if(date > missionEnd) date = missionEnd;
let i = 1;
for(; i < this.steps.length-1; i++){
const {dateOfStart, duration} = this.steps[i];
if(date >= dateOfStart && date < dateOfStart + duration)
break;
}
i = Math.min(i, this.steps.length-2);
const step = this.steps[i];
// Remove the pod sprite from its current group
const pod = <THREE.Sprite>this._spriteObjects[this._podSpriteIndex].pop();
const curAttrId = this.steps[this._podSpriteIndex].attractorId;
const curGroup = this.system.objectsOfBody(curAttrId);
curGroup.remove(pod);
// Add the sprite to the new group
this._spriteObjects[i].push(pod);
this._podSpriteIndex = i;
const newAttrId = step.attractorId;
const newGroup = this.system.objectsOfBody(newAttrId);
newGroup.add(pod);
// Compute its position on the leg arc where the pod is
const orbit = this.orbits[i];
const relDate = date - step.dateOfStart;
const {startM} = step;
const trueAnom = orbit.solveTrueAnomalyAtDate(startM, relDate);
const pos = orbit.positionFromTrueAnomaly(trueAnom);
const {scale} = this.config.rendering;
pod.position.set(pos.x, pos.y, pos.z);
pod.position.multiplyScalar(scale);
}
/**
* Computes and returns the total delta-V of the trajectory
*/

1
src/types.d.ts vendored
View File

@@ -54,6 +54,7 @@ interface OrbitSettings {
interface TrajectoryDrawSettings {
readonly samplePoints: number;
readonly spritesSize: number;
readonly podSpriteSize: number;
}
interface CameraSettings {