如何使用Typescript将网格添加到Forge Viewer v6中? [英] How to add a mesh to forge viewer v6 using Typescript?

查看:158
本文介绍了如何使用Typescript将网格添加到Forge Viewer v6中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道如何使用Type脚本向Forge Viewer v6添加网格.

I need to know how to add meshes to Forge Viewer v6 using Type script.

我浏览了所有主题和文章,并且在v4上运行.

I went through all the topics and articles and it was working with v4.

现在,当我尝试以下代码时:

Now when I try the following code:

    private wallGeometry: THREE.BoxBufferGeometry;

    drawWalls() {

    this.wallGeometry = new THREE.BoxBufferGeometry(4000, 4000, 100, 1, 1, 1);

    console.log('creating wall geometry');

    this.wallGeometry = new THREE.BoxBufferGeometry(4000, 4000, 100, 1, 1, 1);

    console.log('creating wall material');

    let wallMaterial = new THREE.MeshPhongMaterial({ color: 0xff0000 });

    console.log('register wall material');

    this.viewer.impl.matman().addMaterial(
        'dasher-material-vertex',
        wallMaterial,
        true);

    console.log('create Overlay Scene');

    this.viewer.impl.createOverlayScene(this._overlayScene, wallMaterial);

    console.log('wall mesh');

    this.wall = new THREE.Mesh(this.wallGeometry, wallMaterial);
    this.wall.position.set(0, -1000, -2000);

    console.log('add overlay to scene');

    this.addToScene(this.wall);
}

private addToScene(obj: THREE.Object3D) {
    this.viewer.impl.addOverlay(this._overlayScene, obj);
    this.viewer.impl.invalidate(false, false, true);
}

我收到以下错误消息:

THREE.Object3D.add:对象不是THREE.Object3D的实例.
yr {uuid:"6A27DA63-8F99-4E50-9A99-90BED6CE5B85",名称:",类型:"Mesh",父项:null,子项:Array(0),…}
castShadow:false
孩子:[]
drawMode:0
frustumCulled:true
几何:II {uuid:"8C6C2DD2-B233-4E98-998C-2307A84D1E4B",名称:",类型:"BoxBufferGeometry",索引:pi,属性:{…},…}
层数:Pn {mask:1}
材料:hc {uuid:"9A6A3601-49F6-4D6E-98E1-21C35BF63D80",名称:",类型:"MeshPhongMaterial",雾:真,灯光:真,…}
矩阵:dn {元素:Array(16)}
matrixAutoUpdate:true
matrixWorld:dn {元素:Array(16)}
matrixWorldNeedsUpdate:假
名称:"
父级:null
位置:位于{x:0,y:-1000,z:-2000}
四元数:Et {_x:0,_y:0,_z:0,_w:1,onChangeCallback:ƒ}
receiveShadow:假
renderOrder:0
旋转:Cn {_x:0,_y:0,_z:0,_order:"XYZ",onChangeCallback:ƒ}
比例尺:{x:1,y:1,z:1}
类型:网格"
上:在{x:0,y:1,z:0}
userData:{}
uuid:"6A27DA63-8F99-4E50-9A99-90BED6CE5B85"
可见:true
eulerOrder:(...)
id:3
modelViewMatrix:dn {元素:Array(16)}
normalMatrix:Lt {elements:Array(9)}
useQuaternion:(...)
原始:$ n

THREE.Object3D.add: object not an instance of THREE.Object3D.
yr {uuid: "6A27DA63-8F99-4E50-9A99-90BED6CE5B85", name: "", type: "Mesh", parent: null, children: Array(0), …}
castShadow: false
children: []
drawMode: 0
frustumCulled: true
geometry: Ii {uuid: "8C6C2DD2-B233-4E98-998C-2307A84D1E4B", name: "", type: "BoxBufferGeometry", index: pi, attributes: {…}, …}
layers: Pn {mask: 1}
material: hc {uuid: "9A6A3601-49F6-4D6E-98E1-21C35BF63D80", name: "", type: "MeshPhongMaterial", fog: true, lights: true, …}
matrix: dn {elements: Array(16)}
matrixAutoUpdate: true
matrixWorld: dn {elements: Array(16)}
matrixWorldNeedsUpdate: false
name: ""
parent: null
position: At {x: 0, y: -1000, z: -2000}
quaternion: Et {_x: 0, _y: 0, _z: 0, _w: 1, onChangeCallback: ƒ}
receiveShadow: false
renderOrder: 0
rotation: Cn {_x: 0, _y: 0, _z: 0, _order: "XYZ", onChangeCallback: ƒ}
scale: At {x: 1, y: 1, z: 1}
type: "Mesh"
up: At {x: 0, y: 1, z: 0}
userData: {}
uuid: "6A27DA63-8F99-4E50-9A99-90BED6CE5B85"
visible: true
eulerOrder: (...)
id: 3
modelViewMatrix: dn {elements: Array(16)}
normalMatrix: Lt {elements: Array(9)}
useQuaternion: (...)
proto: $n

任何想法?

这是我的DevTools的快照:

This a snapshot from my DevTools:

推荐答案

根据three.js v71

According to three.js v71 source, this error is thrown when the inserted object is missing a property called isObject3D. I'm not sure if the lack of this property could be caused by Forge Viewer. Try putting a breakpoint right before calling addToScene and make sure that the isObject3D property is there.

此外,由于您在运行时期间遇到此错误,因此它也不应该与TypeScript相关.

Also, since you're getting this error during runtime, it should not be related to TypeScript either.

这篇关于如何使用Typescript将网格添加到Forge Viewer v6中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆