MaterialAdapter.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. module INSPECTOR {
  2. export class MaterialAdapter
  3. extends Adapter {
  4. constructor(obj:BABYLON.Material) {
  5. super(obj);
  6. }
  7. /** Returns the name displayed in the tree */
  8. public id() : string {
  9. let str = '';
  10. if (this._obj.name) {
  11. str = this._obj.name;
  12. } // otherwise nothing displayed
  13. return str;
  14. }
  15. /** Returns the type of this object - displayed in the tree */
  16. public type() : string{
  17. return Helpers.GET_TYPE(this._obj);
  18. }
  19. /** Returns the list of properties to be displayed for this adapter */
  20. public getProperties() : Array<PropertyLine> {
  21. let propertiesLines : Array<PropertyLine> = [];
  22. let propToDisplay = [];
  23. // The if is there to work with the min version of babylon
  24. if (this._obj instanceof BABYLON.StandardMaterial) {
  25. propToDisplay = PROPERTIES['StandardMaterial'].properties;
  26. } else if (this._obj instanceof BABYLON.PBRMaterial) {
  27. propToDisplay = PROPERTIES['PBRMaterial'].properties;
  28. }
  29. for (let dirty of propToDisplay) {
  30. let infos = new Property(dirty, this._obj);
  31. propertiesLines.push(new PropertyLine(infos));
  32. }
  33. return propertiesLines;
  34. }
  35. /** No tools for a material adapter */
  36. public getTools() : Array<AbstractTreeTool> {
  37. return [];
  38. }
  39. /** Overrides super.highlight.
  40. * Highlighting a material outlines all meshes linked to this material
  41. */
  42. public highlight(b:boolean) {
  43. let material = this.actualObject as BABYLON.Material;
  44. let meshes = material.getBindedMeshes();
  45. for (let mesh of meshes) {
  46. mesh.renderOutline = b;
  47. mesh.outlineWidth = 0.25;
  48. mesh.outlineColor = BABYLON.Color3.Yellow();
  49. }
  50. }
  51. }
  52. }