Skip to content

Commit

Permalink
Merge pull request #381 from makimenko/stl-loader
Browse files Browse the repository at this point in the history
#375: STL Loader
  • Loading branch information
makimenko authored May 1, 2021
2 parents bbc8097 + 7f034d6 commit 432fab6
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 469 deletions.
2 changes: 1 addition & 1 deletion projects/atft/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "atft",
"version": "1.4.20",
"version": "1.4.21",
"description": "Ready-to-use Angular components for Three.js, see https://makimenko.github.io/angular-template-for-threejs/.",
"keywords": [
"threejs",
Expand Down
7 changes: 5 additions & 2 deletions projects/atft/src/lib/object/loader/atft-loader.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@ import {CommonModule} from '@angular/common';
import {ObjectLoaderComponent} from './object-loader.component';
import {ObjLoaderComponent} from './obj-loader.component';
import {SVGLoaderComponent} from './svg-loader.component';
import {StlLoaderComponent} from './stl-loader.component';


@NgModule({
declarations: [
ObjLoaderComponent,
ObjectLoaderComponent,
SVGLoaderComponent
SVGLoaderComponent,
StlLoaderComponent,
],
imports: [
CommonModule
],
exports: [
ObjLoaderComponent,
ObjectLoaderComponent,
SVGLoaderComponent
SVGLoaderComponent,
StlLoaderComponent,
]
})
export class AtftLoaderModule {
Expand Down
1 change: 1 addition & 0 deletions projects/atft/src/lib/object/loader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export * from './atft-loader.module';
export * from './obj-loader.component';
export * from './object-loader.component';
export * from './svg-loader.component';
export * from './stl-loader.component';
export * from './abstract-model-loader';
export * from './services';
48 changes: 48 additions & 0 deletions projects/atft/src/lib/object/loader/stl-loader.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {Component, Input, Optional, SkipSelf} from '@angular/core';

import * as THREE from 'three';
import {RendererService} from '../../renderer/renderer.service';
import {appliedMaterial, provideParent} from '../../util';
import {AbstractObject3D} from '../abstract-object-3d';
import {AbstractModelLoader} from './abstract-model-loader';
import {STLLoader} from 'three/examples/jsm/loaders/STLLoader';

@Component({
selector: 'atft-stl-loader',
providers: [provideParent(StlLoaderComponent)],
template: '<ng-content></ng-content>'
})
export class StlLoaderComponent extends AbstractModelLoader {
private loader = new STLLoader();

@Input()
material: string;

@Input()
materialColor: string | number = '#FFFFFF';

@Input()
depthWrite = true;

constructor(
protected rendererService: RendererService,
@SkipSelf() @Optional() protected parent: AbstractObject3D<any>
) {
super(rendererService, parent);
}

protected async loadLazyObject() {
// console.log('StlLoaderComponent.loadLazyObject');
return new Promise<THREE.Object3D>((resolve, reject) => {
this.loader.load(this.model, geometry => {
const material = appliedMaterial(this.materialColor, this.material, this.depthWrite);
const mesh = new THREE.Mesh(geometry, material);
resolve(mesh);
},
undefined,
reject
);
});
}

}
466 changes: 0 additions & 466 deletions src/assets/model/tableAndChair.dae

This file was deleted.

17 changes: 17 additions & 0 deletions src/stories/other/loader.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ class StorybookDifferentSVGLoaderComponent {

}

@Component({
template: axesSceneWrapper(`
<atft-stl-loader
model="https://raw.githubusercontent.com/makimenko/files/master/angular-template-for-threejs/model/Stl/Menger_sponge_sample.stl"
materialColor="#AAFFAA"
>
</atft-stl-loader>
`)
})
class StorybookStlLoaderComponent {
}

export default {
title: 'Other/Loader',
decorators: [
Expand Down Expand Up @@ -123,6 +135,11 @@ export const DifferentSvgLoader = (args) => ({
props: args
});

export const StlLoader = (args) => ({
component: StorybookStlLoaderComponent,
props: args
});

SvgLoader.args = {
model: './assets/svg/idea.svg',
overrideMaterialColor: '0xff0000'
Expand Down

0 comments on commit 432fab6

Please sign in to comment.