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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | 4x 4x 4x 33x 33x 33x 4x 29x 3x 26x 2x 24x 2x 22x 43x 43x 31x 4x 27x 5x 22x 2x 20x 2x 18x 3x 15x 3x 12x 2x 10x 7x 3x 2x 1x 1x 12x 43x 4x 4x 2x 2x 3x 3x 2x 2x 5x 5x 5x 7x 7x 3x 3x 3x 3x 4x 4x 5x 5x 3x 3x 3x 6x 9x 9x 3x 3x 1x 1x 12x 12x 12x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 2x 2x 1x 1x 1x 1x 1x 1x 12x 43x 43x 43x 43x 43x 11x 11x 11x 11x 11x 11x 54x 54x | import { Group } from "three"; import { DrawCore, Tag } from "@bitbybit-dev/core"; import * as Inputs from "../inputs"; import { Base } from "@bitbybit-dev/core/lib/api/inputs/base-inputs"; import { Context } from "../context"; import { DrawHelper } from "../draw-helper"; export class Draw extends DrawCore { private defaultBasicOptions = new Inputs.Draw.DrawBasicGeometryOptions(); private defaultPolylineOptions: Inputs.Draw.DrawBasicGeometryOptions = { ...new Inputs.Draw.DrawBasicGeometryOptions(), size: 2, colours: "#ff00ff", }; constructor( private readonly drawHelper: DrawHelper, private readonly context: Context, private readonly tag: Tag ) { super(); } async drawAnyAsync(inputs: Inputs.Draw.DrawAny<Group>): Promise<Group> { const entity = inputs.entity; Iif (entity === undefined || (Array.isArray(entity) && entity.length === 0)) { return Promise.resolve(undefined); } // we start with async ones if (this.detectJscadMesh(entity)) { return this.handleJscadMesh(inputs); } else if (this.detectOcctShape(entity)) { return this.handleOcctShape(inputs); } else if (this.detectOcctShapes(entity)) { return this.handleOcctShapes(inputs); } else if (this.detectJscadMeshes(entity)) { return this.handleJscadMeshes(inputs); } else { // here we have all sync drawer functions return Promise.resolve(this.drawAny(inputs)); } } /** * Draws any kind of geometry that does not need asynchronous computing, thus it cant be used with shapes coming from occt or jscad * @param inputs Contains options and entities to be drawn * @returns ThreeJS Group * @group draw sync * @shortname draw sync */ drawAny(inputs: Inputs.Draw.DrawAny<Group>): Group { let result; const entity = inputs.entity; if (!inputs.group) { if (this.detectLine(entity)) { result = this.handleLine(inputs); } else if (this.detectPoint(entity)) { result = this.handlePoint(inputs); } else if (this.detectPolyline(entity)) { result = this.handlePolyline(inputs); } else if (this.detectVerbCurve(entity)) { result = this.handleVerbCurve(inputs); } else if (this.detectVerbSurface(entity)) { result = this.handleVerbSurface(inputs); } else if (this.detectPolylines(entity)) { result = this.handlePolylines(inputs); } else if (this.detectLines(entity)) { result = this.handleLines(inputs); } else if (this.detectPoints(entity)) { result = this.handlePoints(inputs); } else if (this.detectVerbCurves(entity)) { result = this.handleVerbCurves(inputs); } else if (this.detectVerbSurfaces(entity)) { result = this.handleVerbSurfaces(inputs); } else Eif (this.detectTag(entity)) { result = this.handleTag(inputs); } else if (this.detectTags(entity)) { result = this.handleTags(inputs); } } else { // here types are marked on group metadata so it is not necessary to check their type result = this.updateAny(inputs); } return result; } private handleJscadMesh(inputs: Inputs.Draw.DrawAny<Group>): Promise<Group> { return this.handleAsync(inputs, this.defaultPolylineOptions, (options) => { return this.drawHelper.drawSolidOrPolygonMesh({ jscadMesh: inputs.group, mesh: inputs.entity, ...options as Inputs.Draw.DrawBasicGeometryOptions }); }, Inputs.Draw.drawingTypes.jscadMesh); } private handleJscadMeshes(inputs: Inputs.Draw.DrawAny<Group>): Promise<Group> { return this.handleAsync(inputs, this.defaultPolylineOptions, (options) => { return this.drawHelper.drawSolidOrPolygonMeshes({ jscadMesh: inputs.group, meshes: inputs.entity as any[], ...options as Inputs.Draw.DrawBasicGeometryOptions }); }, Inputs.Draw.drawingTypes.jscadMeshes); } private handleOcctShape(inputs: Inputs.Draw.DrawAny<Group>): Promise<Group> { return this.handleAsync(inputs, new Inputs.OCCT.DrawShapeDto(inputs.entity), (options) => { return this.drawHelper.drawShape({ shape: inputs.entity as Inputs.OCCT.TopoDSShapePointer, ...new Inputs.Draw.DrawOcctShapeOptions(), ...options as Inputs.Draw.DrawOcctShapeOptions }); }, Inputs.Draw.drawingTypes.occt); } private handleOcctShapes(inputs: Inputs.Draw.DrawAny<Group>): Promise<Group> { return this.handleAsync(inputs, new Inputs.OCCT.DrawShapeDto(inputs.entity), (options) => { return this.drawHelper.drawShapes({ shapes: inputs.entity as Inputs.OCCT.TopoDSShapePointer[], ...new Inputs.Draw.DrawOcctShapeOptions(), ...options as Inputs.Draw.DrawOcctShapeOptions }); }, Inputs.Draw.drawingTypes.occtShapes); } private handleLine(inputs: Inputs.Draw.DrawAny<Group>): Group { return this.handle(inputs, this.defaultPolylineOptions, (options) => { const line = inputs.entity as Inputs.Base.Line3; return this.drawHelper.drawPolylinesWithColours({ polylinesMesh: inputs.group, polylines: [{ points: [line.start, line.end] }], ...options as Inputs.Draw.DrawBasicGeometryOptions }); }, Inputs.Draw.drawingTypes.line); } private handlePoint(inputs: Inputs.Draw.DrawAny<Group>) { return this.handle(inputs, this.defaultBasicOptions, (options) => { return this.drawHelper.drawPoint({ pointMesh: inputs.group, point: inputs.entity as Inputs.Base.Point3, ...options as Inputs.Draw.DrawBasicGeometryOptions }); }, Inputs.Draw.drawingTypes.point); } private handlePolyline(inputs: Inputs.Draw.DrawAny<Group>): Group { return this.handle(inputs, this.defaultPolylineOptions, (options) => { return this.drawHelper.drawPolylineClose({ polylineMesh: inputs.group, polyline: inputs.entity, ...options }); }, Inputs.Draw.drawingTypes.polyline); } private handleVerbCurve(inputs: Inputs.Draw.DrawAny<Group>): Group { return this.handle(inputs, this.defaultPolylineOptions, (options) => { return this.drawHelper.drawCurve({ curveMesh: inputs.group, curve: inputs.entity, ...options as Inputs.Draw.DrawBasicGeometryOptions }); }, Inputs.Draw.drawingTypes.verbCurve); } private handleVerbSurface(inputs: Inputs.Draw.DrawAny<Group>): Group { return this.handle(inputs, this.defaultPolylineOptions, (options) => { return this.drawHelper.drawSurface({ surfaceMesh: inputs.group, surface: inputs.entity, ...options as Inputs.Draw.DrawBasicGeometryOptions }); }, Inputs.Draw.drawingTypes.verbSurface); } private handlePolylines(inputs: Inputs.Draw.DrawAny<Group>): Group { return this.handle(inputs, this.defaultPolylineOptions, (options) => { return this.drawHelper.drawPolylinesWithColours({ polylinesMesh: inputs.group, polylines: inputs.entity as Inputs.Base.Polyline3[], ...options as Inputs.Draw.DrawBasicGeometryOptions }); }, Inputs.Draw.drawingTypes.polylines); } private handleLines(inputs: Inputs.Draw.DrawAny<Group>): Group { return this.handle(inputs, this.defaultPolylineOptions, (options) => { const lines = inputs.entity as Inputs.Base.Line3[]; return this.drawHelper.drawPolylinesWithColours({ polylinesMesh: inputs.group, polylines: lines.map(e => ({ points: [e.start, e.end] })), ...options as Inputs.Draw.DrawBasicGeometryOptions }); }, Inputs.Draw.drawingTypes.lines); } private handlePoints(inputs: Inputs.Draw.DrawAny<Group>): Group { return this.handle(inputs, this.defaultPolylineOptions, (options) => { return this.drawHelper.drawPoints({ pointsMesh: inputs.group, points: inputs.entity as Inputs.Base.Point3[], ...options as Inputs.Draw.DrawBasicGeometryOptions }); }, Inputs.Draw.drawingTypes.points); } private handleVerbCurves(inputs: Inputs.Draw.DrawAny<Group>) { return this.handle(inputs, this.defaultPolylineOptions, (options) => { return this.drawHelper.drawCurves({ curvesMesh: inputs.group, curves: inputs.entity as Base.VerbCurve[], ...options as Inputs.Draw.DrawBasicGeometryOptions }); }, Inputs.Draw.drawingTypes.verbCurves); } private handleVerbSurfaces(inputs: Inputs.Draw.DrawAny<Group>): Group { return this.handle(inputs, this.defaultBasicOptions, (options) => { return this.drawHelper.drawSurfacesMultiColour({ surfacesMesh: inputs.group, surfaces: inputs.entity as Base.VerbSurface[], ...options as Inputs.Draw.DrawBasicGeometryOptions }); }, Inputs.Draw.drawingTypes.verbSurfaces); } private handleTag(inputs: Inputs.Draw.DrawAny<Group>) { const options = inputs.options ? inputs.options : { updatable: false, }; const result = this.tag.drawTag({ tagVariable: inputs.group as any, tag: inputs.entity as Inputs.Tag.TagDto, ...options as Inputs.Draw.DrawBasicGeometryOptions }); (result as any).userData = { type: Inputs.Draw.drawingTypes.tag, options }; return result; } private handleTags(inputs: Inputs.Draw.DrawAny<Group>) { const options = inputs.options ? inputs.options : { updatable: false, }; const result = this.tag.drawTags({ tagsVariable: inputs.group as any, tags: inputs.entity as Inputs.Tag.TagDto[], ...options as Inputs.Draw.DrawBasicGeometryOptions }); (result as any).userData = { type: Inputs.Draw.drawingTypes.tags, options }; return result; } private updateAny(inputs: Inputs.Draw.DrawAny<Group>): Group { let result; Eif (inputs.group && inputs.group.userData) { const type = inputs.group.userData.type as Inputs.Draw.drawingTypes; switch (type) { case Inputs.Draw.drawingTypes.point: result = this.handlePoint(inputs); break; case Inputs.Draw.drawingTypes.points: result = this.handlePoints(inputs); break; case Inputs.Draw.drawingTypes.line: result = this.handleLine(inputs); break; case Inputs.Draw.drawingTypes.lines: result = this.handleLines(inputs); break; case Inputs.Draw.drawingTypes.polyline: result = this.handlePolyline(inputs); break; case Inputs.Draw.drawingTypes.polylines: result = this.handlePolylines(inputs); break; case Inputs.Draw.drawingTypes.verbCurve: result = this.handleVerbCurve(inputs); break; case Inputs.Draw.drawingTypes.verbCurves: result = this.handleVerbCurves(inputs); break; case Inputs.Draw.drawingTypes.verbSurface: result = this.handleVerbSurface(inputs); break; case Inputs.Draw.drawingTypes.verbSurfaces: result = this.handleVerbSurfaces(inputs); break; case Inputs.Draw.drawingTypes.tag: result = this.handleTag(inputs); break; case Inputs.Draw.drawingTypes.tags: result = this.handleTags(inputs); break; default: break; } } return result; } private handle(inputs: Inputs.Draw.DrawAny<Group>, defaultOptions: Inputs.Draw.DrawOptions, action: (inputs) => Group, type: Inputs.Draw.drawingTypes): Group { let options = inputs.options ? inputs.options : defaultOptions; Iif (!inputs.options && inputs.group && inputs.group.userData.options) { options = inputs.group.userData.options; } const result = action(options); this.applyGlobalSettingsAndMetadataAndShadowCasting(type, options, result); return result; } private async handleAsync(inputs: Inputs.Draw.DrawAny<Group>, defaultOptions: Inputs.Draw.DrawOptions, action: (inputs) => Promise<Group>, type: Inputs.Draw.drawingTypes): Promise<Group> { let options = inputs.options ? inputs.options : defaultOptions; Iif (!inputs.options && inputs.group && inputs.group.userData.options) { options = inputs.group.userData.options; } const result = action(options); return result.then(r => { this.applyGlobalSettingsAndMetadataAndShadowCasting(type, options, r); return r; }); } private applyGlobalSettingsAndMetadataAndShadowCasting(type: Inputs.Draw.drawingTypes, options: Inputs.Draw.DrawOptions, result: Group) { const typemeta = { type, options }; result.userData = result.userData ? { ...result.userData, ...typemeta } : typemeta; } } |