【发布时间】:2019-06-21 04:27:15
【问题描述】:
我想在我的 Forge Viewer 场景中添加几个额外的灯光,但我找不到任何关于如何实现此目的的示例,到目前为止我的尝试都没有成功。
我知道这篇文章:Add Custom Light for the View and Data API Viewer。这不是我要找的,我不想创建新的灯光预设,我想保留选定的灯光预设并在我的模型周围添加额外的灯光以使其更加明亮。
挖掘viewer3D.js代码发现如下函数:
this.initLights = function ()
{
this.dir_light1 = new three__WEBPACK_IMPORTED_MODULE_30__["DirectionalLight"](_defaultDirLightColor, _defaultLightIntensity);
this.dir_light1.position.copy(_lightDirDefault);
this.highlight_dir_light1 = new three__WEBPACK_IMPORTED_MODULE_30__["DirectionalLight"](_defaultDirLightColor, _defaultLightIntensity);
this.highlight_dir_light1.intensity = 1;
this.highlight_dir_light1.position.copy(_lightDirDefault);
//Note this color will be overridden by various light presets
this.amb_light = new three__WEBPACK_IMPORTED_MODULE_30__["AmbientLight"](_defaultAmbientColor);
this.highlight_amb_light = new three__WEBPACK_IMPORTED_MODULE_30__["AmbientLight"](_defaultAmbientColor);
// Set this list only once, so that we're not constantly creating and deleting arrays each frame.
// See https://www.scirra.com/blog/76/how-to-write-low-garbage-real-time-javascript for why.
// use this.no_lights empty array if no lights are needed.
this.lights = [this.dir_light1, this.amb_light];
this.highlight_lights = [this.highlight_dir_light1, this.highlight_amb_light];
//We do not add the lights to any scene, because we need to use them
//in multiple scenes during progressive render.
//this.scene.add(this.amb_light);
// Attach the light to the camera, so that the light direction is applied in view-space.
// Note:
//
// 1. For directional lights, the direction where the light comes from is determined by
// lightPosition - targetPosition, both in in world-space.
// 2. The default target of dir lights is the world origin.
// 3. Transforming the light object only affects the light position, but has no effect on the target.
//
// The goal is to rotate the lightDir with the camera, but keep it independent
// of the camera position. Due to 3. above, we must also attach the light's target object to the camera.
// Otherwise, the camera position would incorrectly be added to the light direction.
this.camera.add(this.dir_light1);
this.camera.add(this.dir_light1.target);
this.camera.add(this.highlight_dir_light1);
this.camera.add(this.highlight_dir_light1.target);
_lightsInitialized = true;
};
所以我尝试如下创建我的灯,但没有成功:(
const camera = this.viewer.navigation.getCamera()
positions.forEach(pos => {
const light = new THREE.DirectionalLight(0xFF0000, 1.0)
light.target.position.copy(target)
light.position.copy(pos)
camera.add(light)
camera.add(light.target)
})
// no effect ...
【问题讨论】:
标签: autodesk-forge autodesk-viewer