set up some defaults for bins that are not using advanced dimensions so that they can still have a visual of some sort
This commit is contained in:
parent
1d19a7e993
commit
160d2a9d31
5 changed files with 102 additions and 56 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import { RadiansToDegrees } from "common/TrigFunctions";
|
||||
import { Bin } from "models";
|
||||
import { GrainCable } from "models/GrainCable";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
|
|
@ -21,6 +22,19 @@ export interface CableOrbit {
|
|||
assignedCount?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Effective bin dimensions used for cable placement.
|
||||
* Passed in from Bin3dView so that default fallback values are applied
|
||||
* consistently — cables will always match the rendered shell even when
|
||||
* the bin has no advanced dimensions configured.
|
||||
*/
|
||||
export interface BinDims {
|
||||
diameter: number
|
||||
sidewallHeight: number
|
||||
roofHeight: number
|
||||
hopperHeight: number
|
||||
}
|
||||
|
||||
|
||||
function getLayoutFromDiameter(diameterCm: number): CableOrbit[] {
|
||||
const diameterFt = diameterCm / 30.48;
|
||||
|
|
@ -93,34 +107,36 @@ function distributeCables(cableCount: number, layout: CableOrbit[]) {
|
|||
return assigned;
|
||||
};
|
||||
|
||||
function getTopY(radiusFromCenter: number, bin: Bin) {
|
||||
const binRadius = bin.diameter() / 2;
|
||||
function getTopY(radiusFromCenter: number, dims: BinDims) {
|
||||
const binRadius = dims.diameter / 2;
|
||||
|
||||
const distanceFromEdge = binRadius - radiusFromCenter;
|
||||
|
||||
const angleRad = bin.roofAngle() * (Math.PI / 180);
|
||||
// Use the real roof angle when available; when dimensions aren't configured
|
||||
// the angle will be 0 which gives a flat cable top — correct for a default shape.
|
||||
const angleRad = Math.atan((dims.roofHeight) / (binRadius));
|
||||
|
||||
const roofRise = Math.tan(angleRad) * distanceFromEdge;
|
||||
|
||||
return bin.sidewallHeight() / 2 + roofRise;
|
||||
return dims.sidewallHeight / 2 + roofRise;
|
||||
};
|
||||
|
||||
function getBottomY(radiusFromCenter: number, bin: Bin) {
|
||||
const binRadius = bin.diameter() / 2;
|
||||
function getBottomY(radiusFromCenter: number, dims: BinDims) {
|
||||
const binRadius = dims.diameter / 2;
|
||||
|
||||
const distanceFromCenter = binRadius - radiusFromCenter;
|
||||
|
||||
const angleRad = bin.hopperAngle() * (Math.PI / 180);
|
||||
const angleRad = Math.atan((dims.hopperHeight) / (binRadius))
|
||||
|
||||
const hopperDrop = Math.tan(angleRad) * distanceFromCenter;
|
||||
|
||||
const clearance = 60 //this is in cm
|
||||
const clearance = 60; // cm
|
||||
|
||||
return -bin.sidewallHeight() / 2 - hopperDrop + clearance;
|
||||
return -dims.sidewallHeight / 2 - hopperDrop + clearance;
|
||||
};
|
||||
|
||||
|
||||
export function BuildCableData(bin: Bin): CableData[] {
|
||||
export function BuildCableData(bin: Bin, dims: BinDims): CableData[] {
|
||||
const cables = [...(bin.status.grainCables ?? [])];
|
||||
|
||||
if (cables.length === 0) return [];
|
||||
|
|
@ -144,10 +160,9 @@ export function BuildCableData(bin: Bin): CableData[] {
|
|||
return b.celcius.length - a.celcius.length;
|
||||
});
|
||||
|
||||
const layout = getLayoutFromDiameter(bin.diameter());
|
||||
const layout = getLayoutFromDiameter(dims.diameter);
|
||||
const distributed = distributeCables(cables.length, layout);
|
||||
|
||||
|
||||
const cableRadius = 5;
|
||||
|
||||
const result: CableData[] = [];
|
||||
|
|
@ -157,12 +172,12 @@ export function BuildCableData(bin: Bin): CableData[] {
|
|||
distributed.forEach(orbit => {
|
||||
const count = orbit.assignedCount ?? 0;
|
||||
|
||||
const topY = getTopY(orbit.radius, bin)
|
||||
const bottomY = getBottomY(orbit.radius, bin)
|
||||
const topY = getTopY(orbit.radius, dims);
|
||||
const bottomY = getBottomY(orbit.radius, dims);
|
||||
|
||||
if (orbit.orbit === 0 && count > 0) {
|
||||
const cable = cables[cableIndex];
|
||||
if (!cable) return
|
||||
if (!cable) return;
|
||||
result.push({
|
||||
cableIndex: cableIndex,
|
||||
radius: cableRadius,
|
||||
|
|
@ -170,7 +185,7 @@ export function BuildCableData(bin: Bin): CableData[] {
|
|||
bottomPosition: new Vector3(0, bottomY, 0),
|
||||
grainCable: cable
|
||||
});
|
||||
cableIndex++
|
||||
cableIndex++;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -183,11 +198,11 @@ export function BuildCableData(bin: Bin): CableData[] {
|
|||
result.push({
|
||||
cableIndex: cableIndex,
|
||||
radius: cableRadius,
|
||||
topPosition: new Vector3(x,topY,z),
|
||||
bottomPosition: new Vector3(x,bottomY,z),
|
||||
topPosition: new Vector3(x, topY, z),
|
||||
bottomPosition: new Vector3(x, bottomY, z),
|
||||
grainCable: cable
|
||||
});
|
||||
cableIndex++
|
||||
cableIndex++;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue