projects/atft/src/lib/object/loader/svg-loader.component.ts
providers |
provideParent(SVGLoaderComponent)
|
selector | atft-svg-loader |
template |
|
Properties |
|
Methods |
|
Inputs |
Outputs |
Accessors |
constructor(rendererService: RendererService, parent: AbstractObject3D<any>, svgLoader: SvgLoaderService, iconService: IconService)
|
|||||||||||||||
Parameters :
|
centered | |
Type : boolean
|
|
Default value : true
|
|
depthWrite | |
Type : boolean
|
|
Default value : true
|
|
icon | |
Type : string
|
|
isCCW | |
Type : boolean
|
|
Default value : false
|
|
material | |
Type : string
|
|
Default value : 'basic'
|
|
maxX | |
Type : number
|
|
maxY | |
Type : number
|
|
noHoles | |
Type : boolean
|
|
Default value : false
|
|
overrideMaterialColor | |
Type : string | undefined
|
|
model | |
Type : string
|
|
Inherited from
AbstractModelLoader
|
|
Defined in
AbstractModelLoader:21
|
|
The model data source (usually a URI). Settings this property only hides the previous model upon successful loading of the new one. This especially means that if the new data source is invalid, the old model will not be removed from the scene. |
layer | |
Type : number
|
|
Default value : 0
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:42
|
name | |
Type : string
|
|
Default value : uuidv4()
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:40
|
rotateX | |
Type : number
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:24
|
|
Rotation in Euler angles (radians) with order X, Y, Z. |
rotateY | |
Type : number
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:25
|
rotateZ | |
Type : number
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:26
|
scaleX | |
Type : number
|
|
Default value : 1
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:36
|
scaleY | |
Type : number
|
|
Default value : 1
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:37
|
scaleZ | |
Type : number
|
|
Default value : 1
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:38
|
translateX | |
Type : number
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:31
|
|
Translate the geometry. This is typically done as a one time operation, and not during a loop. |
translateY | |
Type : number
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:32
|
translateZ | |
Type : number
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:33
|
changed | |
Type : EventEmitter
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:44
|
Public Async loadLazyObject |
loadLazyObject()
|
Inherited from
AbstractLazyObject3D
|
Defined in
AbstractLazyObject3D:77
|
Returns :
Promise<THREE.Object3D>
|
Protected afterInit |
afterInit()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:33
|
Returns :
void
|
Protected newObject3DInstance |
newObject3DInstance()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:68
|
Returns :
THREE.Object3D
|
ngOnDestroy |
ngOnDestroy()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:62
|
Returns :
void
|
Protected startLoading |
startLoading()
|
Inherited from
AbstractLazyObject3D
|
Defined in
AbstractLazyObject3D:39
|
Returns :
void
|
Public addChild | ||||||
addChild(object: AbstractObject3D<any>)
|
||||||
Inherited from
AbstractObject3D
|
||||||
Defined in
AbstractObject3D:143
|
||||||
Parameters :
Returns :
void
|
Public applyRotation |
applyRotation()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:118
|
Returns :
void
|
Public applyScale |
applyScale()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:135
|
Returns :
void
|
Public applyTranslation |
applyTranslation()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:127
|
Returns :
void
|
Public findByName | ||||||
findByName(name: string)
|
||||||
Inherited from
AbstractObject3D
|
||||||
Defined in
AbstractObject3D:185
|
||||||
Parameters :
Returns :
any
|
Public getChildren |
getChildren()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:202
|
Returns :
Array<AbstractObject3D<any>>
|
Public getObject |
getObject()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:175
|
Returns :
T
|
Public ngAfterViewInit |
ngAfterViewInit()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:181
|
Returns :
void
|
Public ngOnChanges | ||||||
ngOnChanges(changes: SimpleChanges)
|
||||||
Inherited from
AbstractObject3D
|
||||||
Defined in
AbstractObject3D:57
|
||||||
Parameters :
Returns :
void
|
Public ngOnInit |
ngOnInit()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:97
|
Returns :
void
|
Protected recursionByName | |||||||||
recursionByName(currentNode: AbstractObject3D<any>, name: string)
|
|||||||||
Inherited from
AbstractObject3D
|
|||||||||
Defined in
AbstractObject3D:192
|
|||||||||
Parameters :
Returns :
any
|
Public removeChild | ||||||
removeChild(object: AbstractObject3D<any>)
|
||||||
Inherited from
AbstractObject3D
|
||||||
Defined in
AbstractObject3D:160
|
||||||
Parameters :
Returns :
void
|
Public removeChildByName | ||||||
removeChildByName(name: string)
|
||||||
Inherited from
AbstractObject3D
|
||||||
Defined in
AbstractObject3D:206
|
||||||
Parameters :
Returns :
void
|
Public updateParent |
updateParent()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:111
|
Returns :
void
|
Private _overrideMaterialColor |
Type : string | undefined
|
Default value : undefined
|
Protected _model |
Type : string
|
Inherited from
AbstractModelLoader
|
Defined in
AbstractModelLoader:12
|
Protected lazyObject |
Type : THREE.Object3D | undefined
|
Inherited from
AbstractLazyObject3D
|
Defined in
AbstractLazyObject3D:24
|
This is reference to lazy loaded Object3D (async after init) |
Private parentInitialized |
Default value : false
|
Inherited from
AbstractLazyObject3D
|
Defined in
AbstractLazyObject3D:19
|
Flag to signal whether the parentScene class instance AbstractObject3D called the overwritten method AbstractModelLoader yet. Unless that method was called, no methods and properties of AbstractObject3D may be safely accessed, especially AbstractObject3D and AbstractObject3D.renderer. |
Protected childlren |
Type : Array<AbstractObject3D<any>>
|
Default value : []
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:46
|
Protected object |
Type : T
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:48
|
overrideMaterialColor | ||||||
getoverrideMaterialColor()
|
||||||
setoverrideMaterialColor(value: string | undefined)
|
||||||
Parameters :
Returns :
void
|
icon | ||||||
geticon()
|
||||||
seticon(icon: string)
|
||||||
Parameters :
Returns :
void
|
import {Component, Input, Optional, SkipSelf} from '@angular/core';
import {RendererService} from '../../renderer/renderer.service';
import {appliedMaterial, fixCenter, provideParent, scaleToFit} from '../../util';
import {AbstractObject3D} from '../abstract-object-3d';
import {AbstractModelLoader} from './abstract-model-loader';
import {IconService, SvgLoaderService} from './services';
import * as THREE from 'three';
@Component({
selector: 'atft-svg-loader',
providers: [provideParent(SVGLoaderComponent)],
template: '<ng-content></ng-content>'
})
export class SVGLoaderComponent extends AbstractModelLoader {
@Input()
get overrideMaterialColor(): string | undefined {
return this._overrideMaterialColor;
}
set overrideMaterialColor(value: string | undefined) {
this._overrideMaterialColor = value;
if (this.object) {
this.startLoading();
}
}
@Input()
set icon(icon: string) {
// console.log('SVGLoaderComponent.icon', icon);
const iconProvider = this.iconService.getSource(icon);
this.model = iconProvider.url;
this.isCCW = iconProvider.isCCW;
this.noHoles = iconProvider.noHoles;
if (!iconProvider.allowColorOverride) {
this.overrideMaterialColor = undefined;
}
}
get icon(): string {
return this.model;
}
private _overrideMaterialColor: string | undefined = undefined;
@Input()
material = 'basic';
@Input()
depthWrite = true;
@Input()
maxX!: number;
@Input()
maxY!: number;
@Input()
centered = true;
@Input()
isCCW = false;
@Input()
noHoles = false;
constructor(
protected override rendererService: RendererService,
@SkipSelf() @Optional() protected override parent: AbstractObject3D<any>,
protected svgLoader: SvgLoaderService,
protected iconService: IconService
) {
super(rendererService, parent);
}
public async loadLazyObject(): Promise<THREE.Object3D> {
// console.log('SVGLoaderComponent.loadLazyObject', this.model);
const paths = await this.svgLoader.load(this.model);
const group = new THREE.Group();
for (const path of paths) {
const color = (this._overrideMaterialColor ? this._overrideMaterialColor : path.color);
const material = appliedMaterial(color, this.material, this.depthWrite);
const shapes: THREE.Shape[] = path.toShapes(this.isCCW/*, this.noHoles*/);
for (const shape of shapes) {
const geometry = new THREE.ShapeGeometry(shape);
const mesh = new THREE.Mesh(geometry, material);
group.add(mesh);
}
}
if (this.maxX || this.maxY) {
scaleToFit(group, new THREE.Vector3(this.maxX, this.maxY, 0));
}
if (this.centered) {
fixCenter(group);
}
return group;
}
}