All files / app/codeCharta/services/3DExports/3DPreview/MeshModels/BackMeshModels metricDescriptionsContainerMesh.ts

100% Statements 36/36
100% Branches 3/3
100% Functions 7/7
100% Lines 36/36

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98  6x   6x 6x 6x 6x   6x     7x   7x       6x 6x 6x   6x                     6x   6x                     6x   6x                       6x   6x   6x       6x 6x 48x 48x 48x 48x 48x     6x       6x 6x 6x       6x 6x 6x       6x 6x 6x      
import { GeometryOptions } from "../../preview3DPrintMesh"
import { Mesh } from "three"
import { Font } from "three/examples/jsm/loaders/FontLoader"
import { BackPrintColorChangeStrategy } from "../../ColorChangeStrategies/backPrintColorChangeStrategy"
import { MetricDescriptionBlockMesh } from "./metricDescriptionBlockMesh"
import { ColorMetricDescriptionBlockMesh } from "./colorMetricDescriptionBlockMesh"
import { GeneralMesh } from "../generalMesh"
 
export class MetricDescriptionsContainerMesh extends GeneralMesh {
    constructor(
        name: string,
        public font: Font
    ) {
        super(name, new BackPrintColorChangeStrategy())
    }
 
    async init(geometryOptions: GeometryOptions): Promise<MetricDescriptionsContainerMesh> {
        const { areaIcon, areaIconScale } = this.createAreaAttributes()
        const { heightIcon, heightIconScale } = this.createHeightAttributes()
        const { colorIcon, colorIconScale } = this.createColorAttributes()
 
        const heightMetricBlock = await new MetricDescriptionBlockMesh(
            {
                name: "HeigthMetricBlock",
                title: geometryOptions.heightMetricTitle,
                iconFilename: heightIcon,
                iconScale: heightIconScale,
                nodeMetricData: geometryOptions.heightMetricData
            },
            this.font,
            0.05
        ).init(geometryOptions)
        this.add(heightMetricBlock)
 
        const areaMetricBlock = await new MetricDescriptionBlockMesh(
            {
                name: "AreaMetricBlock",
                title: geometryOptions.areaMetricTitle,
                iconFilename: areaIcon,
                iconScale: areaIconScale,
                nodeMetricData: geometryOptions.areaMetricData
            },
            this.font,
            -0.1
        ).init(geometryOptions)
        this.add(areaMetricBlock)
 
        const colorMetricBlock = await new ColorMetricDescriptionBlockMesh(
            {
                name: "ColorMetricBlock",
                title: geometryOptions.colorMetricTitle,
                iconFilename: colorIcon,
                iconScale: colorIconScale,
                nodeMetricData: geometryOptions.colorMetricData,
                colorRange: geometryOptions.colorRange
            },
            this.font,
            -0.25
        ).init(geometryOptions)
        this.add(colorMetricBlock)
 
        this.centerMetricsMeshInXDirection()
 
        return this
    }
 
    private centerMetricsMeshInXDirection() {
        const x = { min: Number.POSITIVE_INFINITY, max: Number.NEGATIVE_INFINITY }
        this.traverse(child => {
            if (child instanceof Mesh && child.visible) {
                child.geometry.computeBoundingBox()
                const { min, max } = child.geometry.boundingBox
                x.min = Math.min(x.min, min.x)
                x.max = Math.max(x.max, max.x)
            }
        })
        this.position.x = (x.max - x.min) / 2
    }
 
    private createColorAttributes() {
        const colorIcon = "color_icon_for_3D_print.svg"
        const colorIconScale = 0.075
        return { colorIcon, colorIconScale }
    }
 
    private createHeightAttributes() {
        const heightIcon = "height_icon_for_3D_print.svg"
        const heightIconScale = 0.09
        return { heightIcon, heightIconScale }
    }
 
    private createAreaAttributes() {
        const areaIcon = "area_icon_for_3D_print.svg"
        const areaIconScale = 0.075
        return { areaIcon, areaIconScale }
    }
}