babylon.multiMaterial.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. var __extends = (this && this.__extends) || function (d, b) {
  2. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  3. function __() { this.constructor = d; }
  4. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5. };
  6. var BABYLON;
  7. (function (BABYLON) {
  8. var MultiMaterial = (function (_super) {
  9. __extends(MultiMaterial, _super);
  10. function MultiMaterial(name, scene) {
  11. _super.call(this, name, scene, true);
  12. this.subMaterials = new Array();
  13. scene.multiMaterials.push(this);
  14. }
  15. // Properties
  16. MultiMaterial.prototype.getSubMaterial = function (index) {
  17. if (index < 0 || index >= this.subMaterials.length) {
  18. return this.getScene().defaultMaterial;
  19. }
  20. return this.subMaterials[index];
  21. };
  22. // Methods
  23. MultiMaterial.prototype.isReady = function (mesh) {
  24. for (var index = 0; index < this.subMaterials.length; index++) {
  25. var subMaterial = this.subMaterials[index];
  26. if (subMaterial) {
  27. if (!this.subMaterials[index].isReady(mesh)) {
  28. return false;
  29. }
  30. }
  31. }
  32. return true;
  33. };
  34. MultiMaterial.prototype.clone = function (name, cloneChildren) {
  35. var newMultiMaterial = new MultiMaterial(name, this.getScene());
  36. for (var index = 0; index < this.subMaterials.length; index++) {
  37. var subMaterial = null;
  38. if (cloneChildren) {
  39. subMaterial = this.subMaterials[index].clone(name + "-" + this.subMaterials[index].name);
  40. }
  41. else {
  42. subMaterial = this.subMaterials[index];
  43. }
  44. newMultiMaterial.subMaterials.push(subMaterial);
  45. }
  46. return newMultiMaterial;
  47. };
  48. MultiMaterial.prototype.serialize = function () {
  49. var serializationObject = {};
  50. serializationObject.name = this.name;
  51. serializationObject.id = this.id;
  52. serializationObject.tags = BABYLON.Tags.GetTags(this);
  53. serializationObject.materials = [];
  54. for (var matIndex = 0; matIndex < this.subMaterials.length; matIndex++) {
  55. var subMat = this.subMaterials[matIndex];
  56. if (subMat) {
  57. serializationObject.materials.push(subMat.id);
  58. }
  59. else {
  60. serializationObject.materials.push(null);
  61. }
  62. }
  63. return serializationObject;
  64. };
  65. return MultiMaterial;
  66. })(BABYLON.Material);
  67. BABYLON.MultiMaterial = MultiMaterial;
  68. })(BABYLON || (BABYLON = {}));