如何在Forge中使用Three.js Sky

时间:2018-07-16 06:20:07

标签: three.js autodesk-forge autodesk-viewer forge

我想在伪造查看器中构建天空场景,我了解了How can you add text to the Forge Viewer with three.js?的方式,所以我使用threejs-full-es6导入Sky,然后再导入新天空,但是当我在场景中添加天空对象时。错误:(THREE.Object3D.add:对象不是THREE.Object3D的实例)。通过这种方式,我发现了新的天空,该对象不同于commen three.js。通过从threejs-full-es6导入sky,该obj只是网格消息。但是命令three.js sky obj包括网格和制服。forge错误:enter image description here three.js: enter image description here

import { Sky,SphereBufferGeometry} from './Three.es.min';

initSky() {
  var sky, sunSphere;
  var scene = viewer.impl.scene;
  sky = new Sky();
  scene.add( sky );
  // Add Sun Helper
  sunSphere = new THREE.Mesh(
      new SphereBufferGeometry( 20000, 16, 8 ),
      new THREE.MeshBasicMaterial( { color: 0xffffff } )
  );
  sunSphere.position.y = - 700000;
  sunSphere.visible = false;
  scene.add( sunSphere );

  /// GUI

  var effectController  = {
      turbidity: 10,
      rayleigh: 2,
      mieCoefficient: 0.005,
      mieDirectionalG: 0.8,
      luminance: 1,
      inclination: 0.49, // elevation / inclination
      azimuth: 0.25, // Facing front,
      sun: ! true
  };

  var distance = 400000;

  function guiChanged() {

      var uniforms = sky.uniforms;
      uniforms.turbidity.value = effectController.turbidity;
      uniforms.rayleigh.value = effectController.rayleigh;
      uniforms.luminance.value = effectController.luminance;
      uniforms.mieCoefficient.value = effectController.mieCoefficient;
      uniforms.mieDirectionalG.value = effectController.mieDirectionalG;

      var theta = Math.PI * ( effectController.inclination - 0.5 );
      var phi = 2 * Math.PI * ( effectController.azimuth - 0.5 );

      sunSphere.position.x = distance * Math.cos( phi );
      sunSphere.position.y = distance * Math.sin( phi ) * Math.sin( theta );
      sunSphere.position.z = distance * Math.sin( phi ) * Math.cos( theta );

      sunSphere.visible = effectController.sun;

      sky.uniforms.sunPosition.value.copy( sunSphere.position );

      renderer.render( scene, camera );

 }



  guiChanged();

}

0 个答案:

没有答案