Skip to content

Commit

Permalink
feat: simplify the Array model
Browse files Browse the repository at this point in the history
  • Loading branch information
ReidyT committed Nov 19, 2024
1 parent d1917dc commit 04bc091
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
Binary file removed models/OriginalFirTree.glb
Binary file not shown.
Binary file removed models/OriginalHouse.glb
Binary file not shown.
Binary file removed models/OriginalResidentialHouse.glb
Binary file not shown.
Binary file removed models/OriginalTree.glb
Binary file not shown.
Binary file modified public/models/HeatLossArrow.glb
Binary file not shown.
36 changes: 21 additions & 15 deletions src/modules/models/HeatLossArrow/HeatLossArrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ const GLB_FILE_PATH = `${MODELS_3D_ROOT_PATH}/HeatLossArrow.glb`;

type GLTFResult = GLTF & {
nodes: {
Arrow_Material001_0: Mesh;
Arrow: Mesh;
};
materials: {
['Material.001']: MeshStandardMaterial;
Arrow: MeshStandardMaterial;
};
};

Expand All @@ -36,26 +36,32 @@ type Props = JSX.IntrinsicElements['group'] & {
position?: Position;
};

// These factors will affect the range of sizes of the arrows.
const MIN_HEATLOSS = 0;
const MAX_HEATLOSS = 5 * powerConversionFactors.KiloWatt;
const MIN_SCALE = 0.8;
const MAX_SCALE = 1.6;

const ARRAY_COLOR = new Color('red');
const TEXT_COLOR = 'white';

export const HeatLossArrow = ({
heatLoss,
position,
...props
}: Props): JSX.Element => {
const { nodes, materials } = useGLTF(GLB_FILE_PATH) as GLTFResult;
const material = materials['Material.001'];

const minHeatLoss = 0;
const maxHeatLoss = 5 * powerConversionFactors.KiloWatt;
const minScale = 0.8;
const maxScale = 1.6;
const material = materials.Arrow;

// const scale = 0.8;
const scale =
minScale +
(maxScale - minScale) *
MIN_SCALE +
(MAX_SCALE - MIN_SCALE) *
Math.min(
1,
Math.max(0.1, (heatLoss - minHeatLoss) / (maxHeatLoss - minHeatLoss)),
Math.max(
0.1,
(heatLoss - MIN_HEATLOSS) / (MAX_HEATLOSS - MIN_HEATLOSS),
),
);

const scaleRef = useRef<Group>(null);
Expand All @@ -69,14 +75,14 @@ export const HeatLossArrow = ({
}
});

material.color = new Color('red');
material.color = ARRAY_COLOR;

return (
<group ref={scaleRef} {...props} position={position} dispose={null}>
<mesh geometry={nodes.Arrow_Material001_0.geometry} material={material} />
<mesh geometry={nodes.Arrow.geometry} material={material} />
<HeatLossTextArrow
heatLoss={formatHeatLossRate(heatLoss)}
color="white"
color={TEXT_COLOR}
/>
</group>
);
Expand Down

0 comments on commit 04bc091

Please sign in to comment.