Comments (5)
Here's an example of a texture loader
constructor(
private loader: NgtLoader,
) {
this.loader.use(TextureLoader, 'assets/uv_grid_opengl.jpg').subscribe(next => {
this.texture = next;
});
}
or FBXLoader
constructor(private loader: NgtLoader) { }
@Input() set url(newvalue: string) {
const s = this.loader.use(FBXLoader, newvalue).subscribe(next => {
const mesh = <Mesh>next.children[0];
this.mesh = mesh;
},
() => { },
() => { s.unsubscribe(); }
);
}
or loading from two files
constructor(private loader: NgtLoader) { }
@Input() set url(newvalue: string) {
const geometry = this.loader.use(OBJLoader, newvalue);
const material = this.loader.use(MTLLoader, newvalue.replace('.obj', '.mtl'));
const s = forkJoin([geometry, material]).subscribe(next => {
next[1].preload()
const materials: Array<Material> = [];
for (let key in next[1].materials) {
materials.push(next[1].materials[key]);
}
this.mesh = <Mesh>next[0].children[0];
this.mesh.material = materials[0];
this.loaded.emit(this.mesh);
},
() => { },
() => { s.unsubscribe(); }
);
}
Hope this helps
from angular-three.
Ok, I got it working by doing the following:
import { NgtLoader, NgtVector3 } from '@angular-three/core';
import { Component, Input } from '@angular/core';
import { Mesh, MeshBasicMaterialParameters } from 'three';
import { AMFLoader, ThreeMFLoader, STLLoader } from 'three-stdlib';
import * as THREE from 'three';
@Component({
...
@Input() set url(newvalue: string) {
const re = /(?:\.([^.]+))?$/;
const ext = re.exec(newvalue);
if (ext?.length) {
switch (ext[1]) {
case '3mf':
let tmf = this.loader.use(ThreeMFLoader, newvalue).subscribe(next => {
let mesh = next.children[0];
while (!mesh.hasOwnProperty("geometry")) {
mesh = mesh.children[0];
}
this.stdmesh = <Mesh>mesh;
}, () => { }, () => { tmf.unsubscribe() });
break;
case 'amf':
let amf = this.loader.use(AMFLoader, newvalue).subscribe(next => {
let mesh = next.children[0];
while (!mesh.hasOwnProperty("geometry")) {
mesh = mesh.children[0];
}
this.stdmesh = <Mesh>mesh;
}, () => { }, () => { amf.unsubscribe() });
break;
case 'stl':
let stl = this.loader.use(STLLoader, newvalue).subscribe(geometry => {
let mesh = geometry;
this.stdmesh = new THREE.Mesh(mesh);
}, () => { }, () => { stl.unsubscribe() });
break;
default:
break;
}
}
}
...
}
Would be nice to have the file types directly integrated/wrapped into angular-three
itself, so that all the other ThreeJS
dependent imports can be removed.
Or maybe I am missing the information on where to find them 😅.
EDIT: fixed unsubscribe parenthesis.
from angular-three.
Glad you got it working.
Wrapping in a library wouldn't simplify your code in any way. The file types are coming from three-stdlib.
You can replace THREE. references to use 'three' import.
I noticed unsubscribe is missing () at end.
from angular-three.
Hey @IRobot1,
Thank you for the correction and you are probably right.
Does this mean, though, that I can and should mix and match properties, functions, types, etc. from angular-three
to/from ThreeJS
?
For example, there is no clear way to attach/detach transformation controls in angular-three
. Should I go the ThreeJS
way in this situation?
from angular-three.
Its fine to mix and match. When using three directly, you're responsible for object cleanup.
I find there usually is a way to do the equivalent in NGT, its not always obvious without a working example.
If you have example code doing something in threejs, I'm always up for the challenge to find a way to do it in NGT. We can move that into repo Discussion area.
If you're happy with answer above, please close issue.
from angular-three.
Related Issues (20)
- Support for threejs r141 HOT 4
- Error: export 'XRRigidTransform' (imported as 'XRRigidTransform') was not found in 'three' HOT 4
- [Feature] Method to remove physics body HOT 1
- [Bug] Objects not added to scene after Enter VR on Oculus Quest HOT 1
- NgtPrimitiveModule not working. "'ngt-primitve' is not a known element" HOT 5
- Angular 14 support HOT 5
- THREE.WebGLRenderer: Context Lost. HOT 1
- 6.0.0-beta HOT 5
- Missing LUT3DEffect error HOT 4
- Cannon JS problem HOT 1
- How to import an glb object with no gemotery prop in node HOT 2
- Can't access useBody internal UUID when adding constraints against instance mesh bodies HOT 2
- NgtSobaOrbitControls missing update HOT 2
- QUESTION: Porting/Wrapping different physics engine "Force Directed layout in 3D" as a new component HOT 2
- THREE.MeshStandardMaterial: 'Uniform' is not a property of this material issue HOT 1
- Cannot load two same GLTF models in component HOT 1
- Bug - Soba Text whiteSpace
- How to deal with the disappearance of gizmo after adding NgtEffectComposer effects? HOT 2
- Issue with achieving the same result as with Threejs HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-three.