Skip to content

Commit

Permalink
Reduce robot model reloading when hiding objects
Browse files Browse the repository at this point in the history
  • Loading branch information
jwbonner committed Oct 6, 2024
1 parent 1a04bbb commit a4362e1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/hub/controllers/ThreeDimensionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,12 +516,22 @@ export default class ThreeDimensionController implements TabController {
}
}

// Get all robot models
let allRobotModels: Set<string> = new Set();
let allSources = this.sourceList.getState();
allSources.forEach((source) => {
if (["robot", "robotLegacy", "ghost", "ghostLegacy", "ghostZebra"].includes(source.type)) {
allRobotModels.add(source.options.model);
}
});

return {
game: this.GAME_SELECT.value,
origin: origin,
objects: objects,
cameraOverride: cameraOverride,
autoDriverStation: getDriverStation(window.log, time!)
autoDriverStation: getDriverStation(window.log, time!),
allRobotModels: [...allRobotModels]
};
}
}
1 change: 1 addition & 0 deletions src/shared/renderers/ThreeDimensionRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export type ThreeDimensionRendererCommand = {
objects: ThreeDimensionRendererCommand_AnyObj[];
cameraOverride: AnnotatedPose3d | null;
autoDriverStation: number;
allRobotModels: string[];
};

export type ThreeDimensionRendererCommand_AnyObj =
Expand Down
18 changes: 18 additions & 0 deletions src/shared/renderers/ThreeDimensionRendererImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,24 @@ export default class ThreeDimensionRendererImpl implements TabRenderer {
}
entry.manager.setObjectData(object);
});
this.objectManagers.forEach((entry) => {
if (!entry.active && (entry.type === "robot" || entry.type === "ghost")) {
let model = (entry.manager as RobotManager).getModel();
if (command.allRobotModels.includes(model)) {
entry.active = true;
entry.manager.setObjectData({
type: entry.type as "robot" | "ghost",
model: model,
color: "#000000",
poses: [],
components: [],
mechanism: null,
visionTargets: [],
swerveStates: []
});
}
}
});
this.objectManagers
.filter((entry) => !entry.active)
.forEach((entry) => {
Expand Down

0 comments on commit a4362e1

Please sign in to comment.