【问题标题】:Adding scene lights to Forge Viewer将场景灯光添加到 Forge Viewer
【发布时间】: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


    【解决方案1】:

    LMV 使用自定义灯光,因此任何额外的光源都需要添加到 viewer.impl.lights 才能生效:

    const myExtraLight = new THREE.DirectionalLight(0xFF0000, 1.0);
    viewer.impl.lights.push(myExtraLight)
    

    请注意,在您发布的查看器源代码中,光源也会添加到渲染器的灯光阵列中:

    this.lights = [this.dir_light1, this.amb_light];
    

    【讨论】:

    • 这似乎没有效果,我添加了一堆红灯 (10),所以我希望看到我的模型以某种方式照亮了一点红色......
    • 这确实有效,我的错,但在我的模型中差异并不明显。我只能注意到金属表面上微小的彩色光反射......
    猜你喜欢
    • 2019-03-14
    • 2015-09-19
    • 2011-12-03
    • 1970-01-01
    • 2020-05-30
    • 2012-07-28
    • 2022-12-14
    • 1970-01-01
    • 2021-06-14
    相关资源
    最近更新 更多