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

100% Statements 21/21
100% Branches 1/1
100% Functions 6/6
100% Lines 21/21

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 407x 7x   7x 7x   7x 17x 17x       6x 6x           6x 6x 6x 6x 6x 6x   6x 6x 6x         3x 3x 3x        
import { GeneralMesh, GeneralSizeChangeMesh } from "./generalMesh"
import { CreateBaseplateGeometryStrategy } from "../CreateGeometryStrategies/createBaseplateGeometryStrategy"
import { GeometryOptions } from "../preview3DPrintMesh"
import { ShaderMaterial } from "three"
import { BaseplateColorChangeStrategy } from "../ColorChangeStrategies/baseplateColorChangeStrategy"
 
export class BaseplateMesh extends GeneralMesh implements GeneralSizeChangeMesh {
    constructor(private createBaseplateGeometryStrategy: CreateBaseplateGeometryStrategy = new CreateBaseplateGeometryStrategy()) {
        super("Baseplate", new BaseplateColorChangeStrategy())
    }
 
    async init(geometryOptions: GeometryOptions): Promise<BaseplateMesh> {
        this.createBaseplateGeometryStrategy.create(geometryOptions).then(geometry => {
            this.geometry = geometry
        })
 
        //at the moment we use a workaround, so we don't need to calculate color, delta, deltaColor and isHeight
        //the downside of this workaround is that there can only be one default color for all objects
        //if its needed that all objects have ShaderMaterial have a look at geometryGenerator.ts
        const shaderMaterial = new ShaderMaterial()
        shaderMaterial.copy(geometryOptions.defaultMaterial)
        shaderMaterial.polygonOffset = true
        shaderMaterial.polygonOffsetUnits = 1
        shaderMaterial.polygonOffsetFactor = 0.1
        this.material = shaderMaterial
 
        this.updateColor(geometryOptions.numberOfColors)
        return new Promise(resolve => {
            resolve(this)
        })
    }
 
    changeSize(geometryOptions: GeometryOptions): void {
        this.boundingBoxCalculated = false
        this.createBaseplateGeometryStrategy.create(geometryOptions).then(geometry => {
            this.geometry = geometry
        })
    }
}