light.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*jshint esversion: 6 */
  2. var blender_light_types = {
  3. point: 0,
  4. sun: 1,
  5. spot: 0,
  6. hemi: 0,
  7. area: 0
  8. };
  9. module.exports = function createThreeJSLamp(blend_lamp) {
  10. let ldata = blend_lamp.data;
  11. let pos_array = [blend_lamp.loc[0], blend_lamp.loc[2], -blend_lamp.loc[1]];
  12. let color = ((ldata.r * 255) << 16) | ((ldata.g * 255) << 8) | ((ldata.b * 255) << 0);
  13. let intesity = ldata.energy;
  14. let distance = 0;
  15. var three_light = null;
  16. switch (ldata.type) {
  17. case blender_light_types.point:
  18. var three_light = new THREE.PointLight(color, intesity, distance);
  19. three_light.position.fromArray(pos_array, 0);
  20. three_light.castShadow = true;
  21. break;
  22. case blender_light_types.sun:
  23. var three_light = new THREE.PointLight(color, intesity, distance);
  24. three_light.position.fromArray(pos_array, 0);
  25. three_light.castShadow = true;
  26. three_light.shadow.mapSize.width = 1024;
  27. three_light.shadow.mapSize.height = 1024;
  28. three_light.shadow.camera.near = 0.01;
  29. three_light.shadow.camera.far = 500;
  30. break;
  31. }
  32. return three_light;
  33. }