DatGui 不想使用 Angular/ThreeJS

大仲马西奥

我尝试使用 DatGui 与立方体(来自名为 CubeComponent 的类)交互到我的 angular App 中,但创建的唯一内容是 DatGui 的一部分,表示打开控制或关闭控制。

感谢您的关注

import {Component, ViewChild, ElementRef} from '@angular/core';
import * as THREE from 'three';
import { MyCubeComponent } from '../assets/cube/cube.component';
import { Camera } from 'three';
import {GUI} from "dat.gui";
import * as dat from 'dat.gui';
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
export class AppComponent {
    @ViewChild('rendererContainer',{static:false}) rendererContainer: ElementRef;
    public scene: THREE.Scene;
    private camera: THREE.PerspectiveCamera;
    renderer = new THREE.WebGLRenderer();
    gui = null;
    cameraGui = null;
    c = new MyCubeComponent();

    private createScene () {
             this.scene = new THREE.Scene();
              this.scene.add(this.c.mesh)
    }
    private createCamera() {
        this.camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 10000);
        this.camera.position.set( 10, 10, 10);
        this.camera.lookAt( 0, -2, 0);
       }
       public datgui() {
const dat = require('dat.gui');
const gui: GUI = new dat.GUI();
this.cameraGui = this.gui.addFolder("camera position");
this.cameraGui.add(this.camera.position, 'x').min(-40).max(40).step(0.25);
this.cameraGui.add(this.camera.position, 'z').min(-40).max(40).step(0.25);
this.cameraGui.open();
       }
    animate() {
    window.requestAnimationFrame(() => this.animate());
    this.renderer.render(this.scene, this.camera);
    }
    render() {
       this.renderer.setSize(window.innerWidth, window.innerHeight);
    this.rendererContainer.nativeElement.appendChild(this.renderer.domElement);
       }
    ngAfterViewInit() {
        this.createScene();
        this.createCamera();
        this.createLight();
        this.render();
        this.animate();
        this.datgui();
    }
}


我在控制台中有一些错误说:null:ERROR null:TypeError:无法读取 null 的属性“addFolder”

或者有时“require”问题(require(“dat gui'))src/app/app.component.ts(63,13)中的错误:错误TS2591:找不到名称'require'

但我在我的帖子中获得了上面的屏幕

马尔基佐

那是因为你在this.gui.addFolder("camera position");定义什么之前就调用this.gui您可能想使用gui.addFolder(),因为您刚刚在上面的一行启动了它。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何为datGUI访问环境光的object3D

静态网站不想使用简单的 POST 端点

使用setText()不想调用textwatcher事件?

不想使用htaccess文件显示Magento主页

.asObservable不想使用Observable.forkJoin

不想使用strip_tags()删除CDATA

MEAN堆栈,我不想使用Jade,如何使用HTML

不想使用if else而是尝试在Python中使用except块

我想使用rtl,但不想使用所有组件

想在vb中使用段落但不想使用标签

不想使用jQuery追加表中的重复行

& 总是使用 HtmlOutput 或 HtmlTemplate 解码(我不想要)

休眠一对多,我不想使用“多实体”主键

我不想使用IEEE 802.11b(CCK)

不想使用printThis库显示打印预览弹出窗口

不想每次计算时都写查询,如何使用变量?

ADO.NET 正在寻找我不想使用的 DbProvider

使用我不想要的公式(= TODAY()-cell)显示的日期

Pjsua(pjsip客户端)不想使用TCP

Java-不想从LIST重复,但使用SET无效

Chromecast不想与VLC 3.0.1一起使用

在 SQL Server 中使用案例时不想要 null

使用组合替换后,如何删除不想要的组合的元组

文字不想在圖像下方。使用引導程序

IDEA不想要使用NOTNULL从的javax,而是使用org.jetbrains

当您不想使用 rest 运算符时正确使用函数“参数”内置关键字

如何在Windows 8上安装C编译器?我不想使用IDE

当我在 C# 中使用“While”时,我不想打印最后的计算

PostgreSQL计划器不想为布尔列使用Bloom Bloom索引