BasicMaterial.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import * as THREE from "../../../libs/three.js/build/three.module.js";
  2. import {Shaders} from "../../../build/shaders/shaders.js";
  3. /* let sid = 0
  4. let getName = ()=>{
  5. return sid ++
  6. } */
  7. class BasicMaterial extends THREE.ShaderMaterial{
  8. constructor(o={}){
  9. super( Object.assign({},{
  10. uniforms:{
  11. color: {type:'v3', value: o.color || new THREE.Color("#FFF")} ,
  12. map: {type: 't', value: o.map },
  13. opacity : {type:'f', value : o.opacity == void 0 ? 1 : o.opacity }
  14. },
  15. vertexShader: Shaders['basicTextured.vs'],
  16. fragmentShader: Shaders['basicTextured.fs'],
  17. defines:{HasColor:'' }
  18. },o))
  19. //this.name111 = getName()
  20. }
  21. copy(source){
  22. super.copy(source)
  23. //console.log('copy', source.name111, this.name111, !!source.map )
  24. this.map = source.map
  25. return this
  26. }
  27. set opacity(o){
  28. this.uniforms && (this.uniforms.opacity.value = o)
  29. }
  30. get opacity(){
  31. return this.uniforms.opacity.value
  32. }
  33. set map(o){
  34. this.uniforms.map.value = o
  35. if(o){
  36. this.defines.HasMap = '';
  37. }else{
  38. delete this.defines.HasMap
  39. }
  40. //可能需要needsUpdate
  41. //console.log('hasMap', !!o, this.name111 )
  42. }
  43. get map(){
  44. return this.uniforms.map.value
  45. }
  46. }
  47. export default BasicMaterial