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 | 7x 7x 7x 7x 7x 7x 17x 17x 17x 17x 17x 17x 16x 14x 14x 14x 14x 14x 10x 16x 14x 14x 12x | import { CustomVisibilityMesh } from "../customVisibilityMesh" import { CreateSvgGeometryStrategy } from "../../CreateGeometryStrategies/createSvgGeometryStrategy" import { GeometryOptions } from "../../preview3DPrintMesh" import { BufferGeometry } from "three" import { Font } from "three/examples/jsm/loaders/FontLoader" import { BackPrintColorChangeStrategy } from "../../ColorChangeStrategies/backPrintColorChangeStrategy" import { CreateTextGeometryStrategy } from "../../CreateGeometryStrategies/createTextGeometryStrategy" import { NodeMetricData } from "../../../../../codeCharta.model" import * as BufferGeometryUtils from "three/examples/jsm/utils/BufferGeometryUtils.js" export interface MetricDescriptionBlockOptions { name: string title: string iconFilename: string iconScale: number nodeMetricData: NodeMetricData } export class MetricDescriptionBlockMesh extends CustomVisibilityMesh { private readonly createSvgGeometryStrategy: CreateSvgGeometryStrategy private readonly createTextGeometryStrategy: CreateTextGeometryStrategy constructor( public metricDescriptionBlockOptions: MetricDescriptionBlockOptions, public font: Font, private yOffset: number ) { super(metricDescriptionBlockOptions.name, new BackPrintColorChangeStrategy(), 200, true) this.createSvgGeometryStrategy = new CreateSvgGeometryStrategy() this.createTextGeometryStrategy = new CreateTextGeometryStrategy() } async init(geometryOptions: GeometryOptions): Promise<MetricDescriptionBlockMesh> { const iconGeometry = await this.createIconGeometry(this.createSvgGeometryStrategy, geometryOptions) const textGeometry = await this.createTextGeometry(this.createTextGeometryStrategy, this.getText(), geometryOptions) this.geometry = BufferGeometryUtils.mergeGeometries([iconGeometry, textGeometry]) this.position.y = -0.15 + this.yOffset this.updateColor(geometryOptions.numberOfColors) return this } async createTextGeometry( createTextGeometryStrategy: CreateTextGeometryStrategy, text: string, geometryOptions: GeometryOptions ): Promise<BufferGeometry> { return createTextGeometryStrategy.create(geometryOptions, { font: this.font, text, side: "back", xPosition: 0.05, yPosition: 0, align: "left" }) } private async createIconGeometry( createSvgGeometryStrategy: CreateSvgGeometryStrategy, geometryOptions: GeometryOptions ): Promise<BufferGeometry> { const iconGeometry = await createSvgGeometryStrategy.create(geometryOptions, { filePath: `codeCharta/assets/${this.metricDescriptionBlockOptions.iconFilename}`, size: this.metricDescriptionBlockOptions.iconScale, side: "back" }) iconGeometry.translate(0, 0, -geometryOptions.baseplateHeight + geometryOptions.printHeight / 2) return iconGeometry } getText(): string { return ( `${this.metricDescriptionBlockOptions.nodeMetricData.name}\n` + `${this.metricDescriptionBlockOptions.title}\n` + `Value range: ${this.metricDescriptionBlockOptions.nodeMetricData.minValue} - ${this.metricDescriptionBlockOptions.nodeMetricData.maxValue}` ) } } |