MeshTab.ts 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2. module INSPECTOR {
  3. export class MeshTab extends PropertyTab {
  4. constructor(tabbar: TabBar, inspector: Inspector) {
  5. super(tabbar, 'Mesh', inspector);
  6. }
  7. /* Overrides super */
  8. protected _getTree(): Array<TreeItem> {
  9. let arr = new Array<TreeItem>();
  10. // Tab containing mesh already in results
  11. let alreadyIn = new Array<BABYLON.Node>();
  12. // Recursive method building the tree panel
  13. let createNode = (obj: BABYLON.Node) => {
  14. let descendants = obj.getDescendants(true);
  15. let node = new TreeItem(this, new MeshAdapter(obj));
  16. if (descendants.length > 0) {
  17. for (let child of descendants) {
  18. if (child instanceof BABYLON.TransformNode) {
  19. if (!Helpers.IsSystemName(child.name)) {
  20. let n = createNode(child);
  21. node.add(n);
  22. }
  23. }
  24. }
  25. node.update();
  26. }
  27. // Retrieve the root node if the mesh is actually child of another mesh
  28. // This can hapen if the child mesh has been created before the parent mesh
  29. if (obj.parent != null && alreadyIn.indexOf(obj) != -1) {
  30. let i: number = 0;
  31. let notFound: boolean = true;
  32. // Find and delete the root node standing for this mesh
  33. while (i < arr.length && notFound) {
  34. if (obj.name === arr[i].id) {
  35. arr.splice(i, 1);
  36. notFound = false;
  37. }
  38. i++;
  39. }
  40. }
  41. alreadyIn.push(obj);
  42. return node;
  43. };
  44. // get all meshes from the first scene
  45. let instances = this._inspector.scene;
  46. // Find top of hierarchy for meshes...
  47. let meshWithoutAnyParent: Array<BABYLON.Node> = [];
  48. for (let mesh of instances.meshes) {
  49. // Not already in the array, not system name and no parent
  50. if (meshWithoutAnyParent.indexOf(mesh) == -1 && !Helpers.IsSystemName(mesh.name) && !mesh.parent) {
  51. meshWithoutAnyParent.push(mesh);
  52. }
  53. }
  54. // ... and for transforms
  55. for (let tn of instances.transformNodes) {
  56. // Not already in the array, not system name and no parent
  57. if (meshWithoutAnyParent.indexOf(tn) == -1 && !Helpers.IsSystemName(tn.name) && !tn.parent) {
  58. meshWithoutAnyParent.push(tn);
  59. }
  60. }
  61. for (let mesh of meshWithoutAnyParent) {
  62. if (alreadyIn.indexOf(mesh) == -1 && !Helpers.IsSystemName(mesh.name)) {
  63. let node = createNode(mesh);
  64. arr.push(node);
  65. }
  66. }
  67. return arr;
  68. }
  69. }
  70. }