首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在有依赖项的角14中包括Three.js

在有依赖项的角14中包括Three.js
EN

Stack Overflow用户
提问于 2022-10-03 15:25:26
回答 1查看 46关注 0票数 0

我目前正在尝试构建一个带有角cli的web应用程序,并使用three.js来使与产品的交互变得有趣,但在某种程度上,即使在看了很多解决方案的视频之后,我仍然无法在角14中包含三个js,它可以与角13一起工作,但即使仍然知道使用角-3的更新,我仍然没有得到结果。结果是将.obj、.glb或任何受支持的文件上传到场景中。有谁能帮我吗?

代码语言:javascript
运行
复制
/* 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));
    }
  }

}
代码语言:javascript
运行
复制
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>

EN

回答 1

Stack Overflow用户

发布于 2022-10-03 16:13:50

此链接中谈论安装

代码语言:javascript
运行
复制
npm install — save three
//and
npm install — save @types/three

它看起来像是在一个角为14的stackblitz中工作

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73937560

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档