babylon.outlineRenderer.js 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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) { _this._effect.setMatrix("world", world); });
  34. };
  35. OutlineRenderer.prototype.isReady = function (subMesh, useInstances) {
  36. var defines = [];
  37. var attribs = [BABYLON.VertexBuffer.PositionKind, BABYLON.VertexBuffer.NormalKind];
  38. var mesh = subMesh.getMesh();
  39. var material = subMesh.getMaterial();
  40. // Alpha test
  41. if (material && material.needAlphaTesting()) {
  42. defines.push("#define ALPHATEST");
  43. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
  44. attribs.push(BABYLON.VertexBuffer.UVKind);
  45. defines.push("#define UV1");
  46. }
  47. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UV2Kind)) {
  48. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  49. defines.push("#define UV2");
  50. }
  51. }
  52. // Bones
  53. if (mesh.useBones) {
  54. attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);
  55. attribs.push(BABYLON.VertexBuffer.MatricesWeightsKind);
  56. defines.push("#define BONES");
  57. defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
  58. }
  59. // Instances
  60. if (useInstances) {
  61. defines.push("#define INSTANCES");
  62. attribs.push("world0");
  63. attribs.push("world1");
  64. attribs.push("world2");
  65. attribs.push("world3");
  66. }
  67. // Get correct effect
  68. var join = defines.join("\n");
  69. if (this._cachedDefines !== join) {
  70. this._cachedDefines = join;
  71. this._effect = this._scene.getEngine().createEffect("outline", attribs, ["world", "mBones", "viewProjection", "diffuseMatrix", "offset", "color"], ["diffuseSampler"], join);
  72. }
  73. return this._effect.isReady();
  74. };
  75. return OutlineRenderer;
  76. })();
  77. BABYLON.OutlineRenderer = OutlineRenderer;
  78. })(BABYLON || (BABYLON = {}));
  79. //# sourceMappingURL=babylon.outlineRenderer.js.map