我目前正在尝试构建一个带有角cli的web应用程序,并使用three.js来使与产品的交互变得有趣,但在某种程度上,即使在看了很多解决方案的视频之后,我仍然无法在角14中包含三个js,它可以与角13一起工作,但即使仍然知道使用角-3的更新,我仍然没有得到结果。结果是将.obj、.glb或任何受支持的文件上传到场景中。有谁能帮我吗?
/* I used the three Library by installing the dependencies using ng add @angular-three/core */
// And I included everything even with the new way of including a file but still the same result, nothing. Plus errors from angular typescript.
import { NgtSobaOrbitControls } from '@angular-three/soba/controls';
import { NgtGLTFLoaderService } from '@angular-three/soba/loaders';
import { Component, Input, OnInit } from '@angular/core';
import { MeshStandardMaterial, Object3D, Mesh, PerspectiveCamera } from 'three';
@Component({
selector: 'app-product-preview',
templateUrl: './three.component.html',
styleUrls: ['./three.component.scss']
})
export class ThreeComponent implements OnInit {
@Input()
set color(value: string) {
this.#color = value;
this.applyColorToMaterial(value);
}
#color = '';
cupMaterial: MeshStandardMaterial | undefined;
constructor(private gltfLoaderService: NgtGLTFLoaderService) {}
cup$ = this.gltfLoaderService.load('assets/toyota.glb');
cupLoaded(object: Object3D) {
this.cupMaterial = <MeshStandardMaterial>(<Mesh>object.getObjectByName('Object_2')).material;
this.applyColorToMaterial(this.#color);
}
ngOnInit() {
}
controlsReady(controls: NgtSobaOrbitControls) {
const orbitControls = controls.controls;
orbitControls.enableZoom = false;
// orbitControls.autoRotate = true;
// orbitControls.autoRotateSpeed = 10;
const camera = orbitControls.object as PerspectiveCamera;
camera.zoom = 10.5;
camera.position.setY(2);
camera.position.setX(30);
}
applyColorToMaterial(color: string) {
if (this.cupMaterial) {
this.cupMaterial.color.setHex(parseInt(color.substring(1), 16));
}
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
发布于 2022-10-03 16:13:50
https://stackoverflow.com/questions/73937560
复制相似问题