Object3DRenderer.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. THREE.WebGLRenderer.Object3DRenderer = function ( lowlevelrenderer, info ) {
  2. this.renderer = lowlevelrenderer;
  3. this.info = info;
  4. };
  5. THREE.extend( THREE.WebGLRenderer.Object3DRenderer.prototype, {
  6. getBufferMaterial: function ( object, geometryGroup ) {
  7. return object.material instanceof THREE.MeshFaceMaterial
  8. ? object.material.materials[ geometryGroup.materialIndex ]
  9. : object.material;
  10. },
  11. bufferGuessUVType: function ( material ) {
  12. // material must use some texture to require uvs
  13. if ( material.map || material.lightMap || material.bumpMap || material.normalMap || material.specularMap || material instanceof THREE.ShaderMaterial ) {
  14. return true;
  15. }
  16. return false;
  17. },
  18. bufferGuessNormalType: function ( material ) {
  19. // only MeshBasicMaterial and MeshDepthMaterial don't need normals
  20. if ( ( material instanceof THREE.MeshBasicMaterial && !material.envMap ) || material instanceof THREE.MeshDepthMaterial ) {
  21. return false;
  22. }
  23. if ( this.materialNeedsSmoothNormals( material ) ) {
  24. return THREE.SmoothShading;
  25. } else {
  26. return THREE.FlatShading;
  27. }
  28. },
  29. materialNeedsSmoothNormals: function ( material ) {
  30. return material && material.shading !== undefined && material.shading === THREE.SmoothShading;
  31. },
  32. bufferGuessVertexColorType: function ( material ) {
  33. if ( material.vertexColors ) {
  34. return material.vertexColors;
  35. }
  36. return false;
  37. },
  38. initCustomAttributes: function ( geometry, object ) {
  39. var nvertices = geometry.vertices.length;
  40. var material = object.material;
  41. if ( material.attributes ) {
  42. if ( geometry.__webglCustomAttributesList === undefined ) {
  43. geometry.__webglCustomAttributesList = [];
  44. }
  45. for ( var a in material.attributes ) {
  46. var attribute = material.attributes[ a ];
  47. if ( !attribute.__webglInitialized || attribute.createUniqueBuffers ) {
  48. attribute.__webglInitialized = true;
  49. var size = 1; // "f" and "i"
  50. if ( attribute.type === "v2" ) size = 2;
  51. else if ( attribute.type === "v3" ) size = 3;
  52. else if ( attribute.type === "v4" ) size = 4;
  53. else if ( attribute.type === "c" ) size = 3;
  54. attribute.size = size;
  55. attribute.array = new Float32Array( nvertices * size );
  56. attribute.buffer = this.renderer.createBuffer();
  57. attribute.buffer.belongsToAttribute = a;
  58. attribute.needsUpdate = true;
  59. }
  60. geometry.__webglCustomAttributesList.push( attribute );
  61. }
  62. }
  63. },
  64. numericalSort: function ( a, b ) {
  65. return b[ 0 ] - a[ 0 ];
  66. }
  67. } );