如何在Autodesk Forge中设置Skybox [英] How to set up skybox in Autodesk Forge
问题描述
我想在我的Forge场景中添加一个天空盒,但是Forge与three.js不同.我想知道我能做些什么.
I want to add a skybox to my Forge scene, but Forge is different from three.js. I want to know what I can do for it.
我尝试了new THREE.CubeTextureLoader
,但是Forge中的three.js没有此功能.然后我尝试构建一个CubeGeometry
,但是效果不佳.
I have tried new THREE.CubeTextureLoader
, but the three.js in Forge doesn't have this function. Then I tried to build a CubeGeometry
, but it did't work well.
这是我的代码:
var materialArr=[];
var directions = ["aa_RT","aa_LF","aa_UP","aa_DN","aa_FR","aa_BK"] ;
for (var i = 0; i < 6; i++){
materialArray.push( new THREE.MeshBasicMaterial({
map: THREE.ImageUtils.loadTexture( "lib/img/aa/"+ directions[i] + ".jpg" ),
side: THREE.BackSide
}));
}
var skyBoxGeom = new THREE.CubeGeometry(80,80,80);
var skyBoxMaterial = new THREE.MeshFaceMaterial(materialArr);
var skyBox = new THREE.Mesh(skyBoxGeom,skyBoxMaterial);
viewer.impl.scene.add(skyBox);
这是我的场景:
推荐答案
以下是一些代码,用于创建适用于查看器的Skybox(在ES6中):
Here is some code for creating a skybox that works for the viewer (in ES6):
export default class ViewerSkybox {
constructor (viewer, options) {
const faceMaterials = options.imageList.map((url) => {
return new THREE.MeshBasicMaterial({
map: THREE.ImageUtils.loadTexture(url),
side: THREE.BackSide
})
})
const skyMaterial = new THREE.MeshFaceMaterial(
faceMaterials)
const geometry = new THREE.CubeGeometry(
options.size.x,
options.size.y,
options.size.z,
1, 1, 1,
null, true)
const skybox = new THREE.Mesh(
geometry, skyMaterial)
viewer.impl.scene.add(skybox)
}
}
这对我来说很好,正如您在我创建的实时演示中看到的那样这里.
This is working fine on my side, as you can see in the live demo I created here.
您需要注意的一件事是,查看器使用基于加载的模型边界框创建的近/远剪切平面.您的Skybox可能比模型大得多,因此一种解决方法是加载更大范围的第二个模型,以便场景修剪平面自动更新.第二个模型仅包含按所需范围放置的微小立方体,例如[(-500,-500,-500),(500,500,500)].
One thing you need to take care about is that the viewer uses near/far clipping planes which are created based on the loaded model bounding box. Your skybox is probably much bigger than the model, so one workaround is to load a second model with a much bigger extents, so the scene clipping planes are updated automatically. The second model only contains tiny cubes placed at the desired extents, for example [(-500, -500, -500), (500, 500, 500)].
The source of my extension using the skybox is here: Viewing.Extension.Showcase.
这篇关于如何在Autodesk Forge中设置Skybox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!