GLTFTab.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /// <reference path="../../../dist/preview release/gltf2Interface/babylon.glTF2Interface.d.ts"/>
  2. /// <reference path="../../../dist/preview release/serializers/babylon.glTF2Serializer.d.ts"/>
  3. module INSPECTOR {
  4. export class GLTFTab extends Tab {
  5. constructor(tabbar: TabBar, inspector: Inspector) {
  6. super(tabbar, 'GLTF');
  7. this._panel = Helpers.CreateDiv('tab-panel') as HTMLDivElement;
  8. const actions = Helpers.CreateDiv('gltf-actions', this._panel) as HTMLDivElement;
  9. this._addExport(inspector, actions);
  10. }
  11. public dispose() {
  12. // Nothing to dispose
  13. }
  14. private _addExport(inspector: Inspector, actions: HTMLDivElement) {
  15. const title = Helpers.CreateDiv('gltf-title', actions);
  16. title.textContent = 'Export';
  17. const name = Helpers.CreateInput('gltf-input', actions);
  18. name.placeholder = "File name...";
  19. const button = Helpers.CreateElement('button', 'gltf-button', actions) as HTMLButtonElement;
  20. button.innerText = 'Export GLB';
  21. button.addEventListener('click', () => {
  22. const data = BABYLON.GLTF2Export.GLB(inspector.scene, name.value || "scene", {
  23. shouldExportMesh: mesh => !GLTFTab._IsSkyBox(mesh)
  24. });
  25. if (data) {
  26. data.downloadFiles();
  27. }
  28. });
  29. }
  30. private static _IsSkyBox(transformNode: BABYLON.TransformNode): boolean {
  31. if (transformNode instanceof BABYLON.Mesh) {
  32. if (transformNode.material) {
  33. const material = transformNode.material as BABYLON.PBRMaterial | BABYLON.StandardMaterial;
  34. const reflectionTexture = material.reflectionTexture;
  35. if (reflectionTexture && reflectionTexture.coordinatesMode === BABYLON.Texture.SKYBOX_MODE) {
  36. return true;
  37. }
  38. }
  39. }
  40. return false;
  41. }
  42. }
  43. }