Git Product home page Git Product logo

Comments (5)

IRobot1 avatar IRobot1 commented on June 26, 2024

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.

short-circuit avatar short-circuit commented on June 26, 2024

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.

IRobot1 avatar IRobot1 commented on June 26, 2024

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.

short-circuit avatar short-circuit commented on June 26, 2024

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.

IRobot1 avatar IRobot1 commented on June 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.