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 | 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 36x 6x 6x 4x 4x 6x 6x 6x 6x 6x 6x 36x 36x 36x 36x 36x 36x 30x 6x | import { GeometryOptions } from "../../preview3DPrintMesh"
import { Font } from "three/examples/jsm/loaders/FontLoader"
import { BackPrintColorChangeStrategy } from "../../ColorChangeStrategies/backPrintColorChangeStrategy"
import { CreateTextGeometryStrategy, CreateTextGeometryStrategyOptions } from "../../CreateGeometryStrategies/createTextGeometryStrategy"
import { ColorRange } from "../../../../../codeCharta.model"
import { MetricDescriptionBlockMesh, MetricDescriptionBlockOptions } from "./metricDescriptionBlockMesh"
import { TextMesh } from "../textMesh"
import { PositivePrintColorChangeStrategy } from "../../ColorChangeStrategies/positivePrintColorChangeStrategy"
import { NeutralPrintColorChangeStrategy } from "../../ColorChangeStrategies/neutralPrintColorChangeStrategy"
import { NegativePrintColorChangeStrategy } from "../../ColorChangeStrategies/negativePrintColorChangeStrategy"
export interface ColorMetricDescriptionBlockOptions extends MetricDescriptionBlockOptions {
colorRange: ColorRange
}
export class ColorMetricDescriptionBlockMesh extends MetricDescriptionBlockMesh {
constructor(colorMetricDescriptionBlockOptions: ColorMetricDescriptionBlockOptions, font: Font, yOffset: number) {
super(colorMetricDescriptionBlockOptions, font, yOffset)
}
async init(geometryOptions: GeometryOptions): Promise<ColorMetricDescriptionBlockMesh> {
const coloredBackTextChildren = await this.createColoredBackTextChildren(geometryOptions)
for (const child of coloredBackTextChildren) {
this.add(child)
}
super.init(geometryOptions)
return this
}
async createTextGeometry(createTextGeometryStrategy: CreateTextGeometryStrategy, text: string, geometryOptions: GeometryOptions) {
return createTextGeometryStrategy.create(geometryOptions, {
font: this.font,
text,
side: "back",
xPosition: 0.05,
yPosition: 0.015,
align: "left"
})
}
getText() {
return `${this.metricDescriptionBlockOptions.nodeMetricData.name}\n` + `${this.metricDescriptionBlockOptions.title}\n`
}
private async createColoredBackTextChildren(geometryOptions: GeometryOptions) {
const colorMetricDescriptionBlockOptions = this.metricDescriptionBlockOptions as ColorMetricDescriptionBlockOptions
const colorTextGeometries = []
const colorTextValueRanges = [
`Value ranges:`,
`${colorMetricDescriptionBlockOptions.nodeMetricData.minValue} - ${colorMetricDescriptionBlockOptions.colorRange.from - 1}`,
`/`,
`${colorMetricDescriptionBlockOptions.colorRange.from} - ${colorMetricDescriptionBlockOptions.colorRange.to - 1}`,
`/`,
`${colorMetricDescriptionBlockOptions.colorRange.to} - ${colorMetricDescriptionBlockOptions.nodeMetricData.maxValue}`
]
const colorChangeStrategies = [
new BackPrintColorChangeStrategy(),
new PositivePrintColorChangeStrategy(),
new BackPrintColorChangeStrategy(),
new NeutralPrintColorChangeStrategy(),
new BackPrintColorChangeStrategy(),
new NegativePrintColorChangeStrategy()
]
let xOffset = 0.05
for (let index = 0; index < colorTextValueRanges.length; index += 1) {
const name = `ColorMetricLastLine${index}`
const createTextGeometryStrategyOptions: CreateTextGeometryStrategyOptions = {
font: this.font,
text: colorTextValueRanges[index],
side: "back",
xPosition: xOffset,
yPosition: -0.045,
align: "left"
}
const textMesh = await new TextMesh(name, colorChangeStrategies[index], 200, true, createTextGeometryStrategyOptions).init(
geometryOptions
)
this.updateColor(geometryOptions.numberOfColors)
colorTextGeometries.push(textMesh)
if (index !== colorTextValueRanges.length - 1) {
xOffset += textMesh.getWidth() + 0.03
}
}
return colorTextGeometries
}
}
|