babylon.outlineRenderer.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var OutlineRenderer = (function () {
  4. function OutlineRenderer(scene) {
  5. this._scene = scene;
  6. }
  7. OutlineRenderer.prototype.render = function (subMesh, batch, useOverlay) {
  8. var _this = this;
  9. if (useOverlay === void 0) { useOverlay = false; }
  10. var scene = this._scene;
  11. var engine = this._scene.getEngine();
  12. var hardwareInstancedRendering = (engine.getCaps().instancedArrays !== null) && (batch.visibleInstances[subMesh._id] !== null) && (batch.visibleInstances[subMesh._id] !== undefined);
  13. if (!this.isReady(subMesh, hardwareInstancedRendering)) {
  14. return;
  15. }
  16. var mesh = subMesh.getRenderingMesh();
  17. var material = subMesh.getMaterial();
  18. engine.enableEffect(this._effect);
  19. this._effect.setFloat("offset", useOverlay ? 0 : mesh.outlineWidth);
  20. this._effect.setColor4("color", useOverlay ? mesh.overlayColor : mesh.outlineColor, useOverlay ? mesh.overlayAlpha : 1.0);
  21. this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
  22. // Bones
  23. if (mesh.useBones) {
  24. this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices());
  25. }
  26. mesh._bind(subMesh, this._effect, BABYLON.Material.TriangleFillMode);
  27. // Alpha test
  28. if (material && material.needAlphaTesting()) {
  29. var alphaTexture = material.getAlphaTestTexture();
  30. this._effect.setTexture("diffuseSampler", alphaTexture);
  31. this._effect.setMatrix("diffuseMatrix", alphaTexture.getTextureMatrix());
  32. }
  33. mesh._processRendering(subMesh, this._effect, BABYLON.Material.TriangleFillMode, batch, hardwareInstancedRendering, function (isInstance, world) {
  34. _this._effect.setMatrix("world", world);
  35. });
  36. };
  37. OutlineRenderer.prototype.isReady = function (subMesh, useInstances) {
  38. var defines = [];
  39. var attribs = [BABYLON.VertexBuffer.PositionKind, BABYLON.VertexBuffer.NormalKind];
  40. var mesh = subMesh.getMesh();
  41. var material = subMesh.getMaterial();
  42. // Alpha test
  43. if (material && material.needAlphaTesting()) {
  44. defines.push("#define ALPHATEST");
  45. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
  46. attribs.push(BABYLON.VertexBuffer.UVKind);
  47. defines.push("#define UV1");
  48. }
  49. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UV2Kind)) {
  50. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  51. defines.push("#define UV2");
  52. }
  53. }
  54. // Bones
  55. if (mesh.useBones) {
  56. attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);
  57. attribs.push(BABYLON.VertexBuffer.MatricesWeightsKind);
  58. defines.push("#define BONES");
  59. defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
  60. }
  61. // Instances
  62. if (useInstances) {
  63. defines.push("#define INSTANCES");
  64. attribs.push("world0");
  65. attribs.push("world1");
  66. attribs.push("world2");
  67. attribs.push("world3");
  68. }
  69. // Get correct effect
  70. var join = defines.join("\n");
  71. if (this._cachedDefines !== join) {
  72. this._cachedDefines = join;
  73. this._effect = this._scene.getEngine().createEffect("outline", attribs, ["world", "mBones", "viewProjection", "diffuseMatrix", "offset", "color"], ["diffuseSampler"], join);
  74. }
  75. return this._effect.isReady();
  76. };
  77. return OutlineRenderer;
  78. })();
  79. BABYLON.OutlineRenderer = OutlineRenderer;
  80. })(BABYLON || (BABYLON = {}));
  81. //# sourceMappingURL=babylon.outlineRenderer.js.map