2
0

ShadowMesh.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. console.warn( "THREE.ShadowMesh: As part of the transition to ES6 Modules, the files in 'examples/js' were deprecated in May 2020 (r117) and will be deleted in December 2020 (r124). You can find more information about developing using ES6 Modules in https://threejs.org/docs/#manual/en/introduction/Installation." );
  2. /**
  3. * A shadow Mesh that follows a shadow-casting Mesh in the scene, but is confined to a single plane.
  4. */
  5. THREE.ShadowMesh = function ( mesh ) {
  6. var shadowMaterial = new THREE.MeshBasicMaterial( {
  7. color: 0x000000,
  8. transparent: true,
  9. opacity: 0.6,
  10. depthWrite: false
  11. } );
  12. THREE.Mesh.call( this, mesh.geometry, shadowMaterial );
  13. this.meshMatrix = mesh.matrixWorld;
  14. this.frustumCulled = false;
  15. this.matrixAutoUpdate = false;
  16. };
  17. THREE.ShadowMesh.prototype = Object.create( THREE.Mesh.prototype );
  18. THREE.ShadowMesh.prototype.constructor = THREE.ShadowMesh;
  19. THREE.ShadowMesh.prototype.update = function () {
  20. var shadowMatrix = new THREE.Matrix4();
  21. return function ( plane, lightPosition4D ) {
  22. // based on https://www.opengl.org/archives/resources/features/StencilTalk/tsld021.htm
  23. var dot = plane.normal.x * lightPosition4D.x +
  24. plane.normal.y * lightPosition4D.y +
  25. plane.normal.z * lightPosition4D.z +
  26. - plane.constant * lightPosition4D.w;
  27. var sme = shadowMatrix.elements;
  28. sme[ 0 ] = dot - lightPosition4D.x * plane.normal.x;
  29. sme[ 4 ] = - lightPosition4D.x * plane.normal.y;
  30. sme[ 8 ] = - lightPosition4D.x * plane.normal.z;
  31. sme[ 12 ] = - lightPosition4D.x * - plane.constant;
  32. sme[ 1 ] = - lightPosition4D.y * plane.normal.x;
  33. sme[ 5 ] = dot - lightPosition4D.y * plane.normal.y;
  34. sme[ 9 ] = - lightPosition4D.y * plane.normal.z;
  35. sme[ 13 ] = - lightPosition4D.y * - plane.constant;
  36. sme[ 2 ] = - lightPosition4D.z * plane.normal.x;
  37. sme[ 6 ] = - lightPosition4D.z * plane.normal.y;
  38. sme[ 10 ] = dot - lightPosition4D.z * plane.normal.z;
  39. sme[ 14 ] = - lightPosition4D.z * - plane.constant;
  40. sme[ 3 ] = - lightPosition4D.w * plane.normal.x;
  41. sme[ 7 ] = - lightPosition4D.w * plane.normal.y;
  42. sme[ 11 ] = - lightPosition4D.w * plane.normal.z;
  43. sme[ 15 ] = dot - lightPosition4D.w * - plane.constant;
  44. this.matrix.multiplyMatrices( shadowMatrix, this.meshMatrix );
  45. };
  46. }();