debugTabComponent.tsx 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import * as React from "react";
  2. import { PaneComponent, IPaneComponentProps } from "../paneComponent";
  3. import { LineContainerComponent } from "../lineContainerComponent";
  4. import { CheckBoxLineComponent } from "../lines/checkBoxLineComponent";
  5. import { GridPropertyGridComponent } from "./propertyGrids/gridPropertyGridComponent";
  6. export class DebugTabComponent extends PaneComponent {
  7. private _skeletonViewersEnabled = false;
  8. private _physicsViewersEnabled = false;
  9. private _skeletonViewers = new Array<BABYLON.Debug.SkeletonViewer>();
  10. constructor(props: IPaneComponentProps) {
  11. super(props);
  12. }
  13. componentWillMount() {
  14. const scene = this.props.scene;
  15. if (!scene) {
  16. return;
  17. }
  18. if (!scene.reservedDataStore) {
  19. scene.reservedDataStore = {};
  20. }
  21. for (var mesh of scene.meshes) {
  22. if (mesh.skeleton && mesh.reservedDataStore && mesh.reservedDataStore.skeletonViewer) {
  23. this._skeletonViewers.push(mesh.reservedDataStore.skeletonViewer);
  24. }
  25. }
  26. this._skeletonViewersEnabled = (this._skeletonViewers.length > 0);
  27. this._physicsViewersEnabled = scene.reservedDataStore.physicsViewer != null;
  28. }
  29. componentWillUnmount() {
  30. }
  31. switchSkeletonViewers() {
  32. this._skeletonViewersEnabled = !this._skeletonViewersEnabled;
  33. const scene = this.props.scene;
  34. if (this._skeletonViewersEnabled) {
  35. for (var mesh of scene.meshes) {
  36. if (mesh.skeleton) {
  37. var found = false;
  38. for (var sIndex = 0; sIndex < this._skeletonViewers.length; sIndex++) {
  39. if (this._skeletonViewers[sIndex].skeleton === mesh.skeleton) {
  40. found = true;
  41. break;
  42. }
  43. }
  44. if (found) {
  45. continue;
  46. }
  47. var viewer = new BABYLON.Debug.SkeletonViewer(mesh.skeleton, mesh, scene, true, 0);
  48. viewer.isEnabled = true;
  49. this._skeletonViewers.push(viewer);
  50. if (!mesh.reservedDataStore) {
  51. mesh.reservedDataStore = {};
  52. }
  53. mesh.reservedDataStore.skeletonViewer = viewer;
  54. }
  55. }
  56. } else {
  57. for (var index = 0; index < this._skeletonViewers.length; index++) {
  58. this._skeletonViewers[index].mesh.reservedDataStore.skeletonViewer = null;
  59. this._skeletonViewers[index].dispose();
  60. }
  61. this._skeletonViewers = [];
  62. }
  63. }
  64. switchPhysicsViewers() {
  65. this._physicsViewersEnabled = !this._physicsViewersEnabled;
  66. const scene = this.props.scene;
  67. if (this._physicsViewersEnabled) {
  68. const physicsViewer = new BABYLON.Debug.PhysicsViewer(scene);
  69. scene.reservedDataStore.physicsViewer = physicsViewer;
  70. for (var mesh of scene.meshes) {
  71. if (mesh.physicsImpostor) {
  72. let debugMesh = physicsViewer.showImpostor(mesh.physicsImpostor);
  73. if (debugMesh) {
  74. debugMesh.reservedDataStore = { hidden: true };
  75. debugMesh.material!.reservedDataStore = { hidden: true };
  76. }
  77. }
  78. }
  79. } else {
  80. scene.reservedDataStore.physicsViewer.dispose();
  81. scene.reservedDataStore.physicsViewer = null;
  82. }
  83. }
  84. render() {
  85. const scene = this.props.scene;
  86. if (!scene) {
  87. return null;
  88. }
  89. return (
  90. <div className="pane">
  91. <LineContainerComponent title="HELPERS">
  92. <GridPropertyGridComponent scene={scene} />
  93. <CheckBoxLineComponent label="Bones" isSelected={() => this._skeletonViewersEnabled} onSelect={() => this.switchSkeletonViewers()} />
  94. <CheckBoxLineComponent label="Physics" isSelected={() => this._physicsViewersEnabled} onSelect={() => this.switchPhysicsViewers()} />
  95. </LineContainerComponent>
  96. <LineContainerComponent title="TEXTURE CHANNELS">
  97. <CheckBoxLineComponent label="Diffuse" isSelected={() => BABYLON.StandardMaterial.DiffuseTextureEnabled} onSelect={() => BABYLON.StandardMaterial.DiffuseTextureEnabled = !BABYLON.StandardMaterial.DiffuseTextureEnabled} />
  98. <CheckBoxLineComponent label="Ambient" isSelected={() => BABYLON.StandardMaterial.AmbientTextureEnabled} onSelect={() => BABYLON.StandardMaterial.AmbientTextureEnabled = !BABYLON.StandardMaterial.AmbientTextureEnabled} />
  99. <CheckBoxLineComponent label="Specular" isSelected={() => BABYLON.StandardMaterial.SpecularTextureEnabled} onSelect={() => BABYLON.StandardMaterial.SpecularTextureEnabled = !BABYLON.StandardMaterial.SpecularTextureEnabled} />
  100. <CheckBoxLineComponent label="Emissive" isSelected={() => BABYLON.StandardMaterial.EmissiveTextureEnabled} onSelect={() => BABYLON.StandardMaterial.EmissiveTextureEnabled = !BABYLON.StandardMaterial.EmissiveTextureEnabled} />
  101. <CheckBoxLineComponent label="Bump" isSelected={() => BABYLON.StandardMaterial.BumpTextureEnabled} onSelect={() => BABYLON.StandardMaterial.BumpTextureEnabled = !BABYLON.StandardMaterial.BumpTextureEnabled} />
  102. <CheckBoxLineComponent label="Opacity" isSelected={() => BABYLON.StandardMaterial.OpacityTextureEnabled} onSelect={() => BABYLON.StandardMaterial.OpacityTextureEnabled = !BABYLON.StandardMaterial.OpacityTextureEnabled} />
  103. <CheckBoxLineComponent label="Reflection" isSelected={() => BABYLON.StandardMaterial.ReflectionTextureEnabled} onSelect={() => BABYLON.StandardMaterial.ReflectionTextureEnabled = !BABYLON.StandardMaterial.ReflectionTextureEnabled} />
  104. <CheckBoxLineComponent label="Refraction" isSelected={() => BABYLON.StandardMaterial.RefractionTextureEnabled} onSelect={() => BABYLON.StandardMaterial.RefractionTextureEnabled = !BABYLON.StandardMaterial.RefractionTextureEnabled} />
  105. <CheckBoxLineComponent label="ColorGrading" isSelected={() => BABYLON.StandardMaterial.ColorGradingTextureEnabled} onSelect={() => BABYLON.StandardMaterial.ColorGradingTextureEnabled = !BABYLON.StandardMaterial.ColorGradingTextureEnabled} />
  106. <CheckBoxLineComponent label="Lightmap" isSelected={() => BABYLON.StandardMaterial.LightmapTextureEnabled} onSelect={() => BABYLON.StandardMaterial.LightmapTextureEnabled = !BABYLON.StandardMaterial.LightmapTextureEnabled} />
  107. <CheckBoxLineComponent label="Fresnel" isSelected={() => BABYLON.StandardMaterial.FresnelEnabled} onSelect={() => BABYLON.StandardMaterial.FresnelEnabled = !BABYLON.StandardMaterial.FresnelEnabled} />
  108. </LineContainerComponent>
  109. <LineContainerComponent title="FEATURES">
  110. <CheckBoxLineComponent label="Animations" isSelected={() => scene.animationsEnabled} onSelect={() => scene.animationsEnabled = !scene.animationsEnabled} />
  111. <CheckBoxLineComponent label="Collisions" isSelected={() => scene.collisionsEnabled} onSelect={() => scene.collisionsEnabled = !scene.collisionsEnabled} />
  112. <CheckBoxLineComponent label="Fog" isSelected={() => scene.fogEnabled} onSelect={() => scene.fogEnabled = !scene.fogEnabled} />
  113. <CheckBoxLineComponent label="Lens flares" isSelected={() => scene.lensFlaresEnabled} onSelect={() => scene.lensFlaresEnabled = !scene.lensFlaresEnabled} />
  114. <CheckBoxLineComponent label="Lights" isSelected={() => scene.lightsEnabled} onSelect={() => scene.lightsEnabled = !scene.lightsEnabled} />
  115. <CheckBoxLineComponent label="Particles" isSelected={() => scene.particlesEnabled} onSelect={() => scene.particlesEnabled = !scene.particlesEnabled} />
  116. <CheckBoxLineComponent label="Post-processes" isSelected={() => scene.postProcessesEnabled} onSelect={() => scene.postProcessesEnabled = !scene.postProcessesEnabled} />
  117. <CheckBoxLineComponent label="Probes" isSelected={() => scene.probesEnabled} onSelect={() => scene.probesEnabled = !scene.probesEnabled} />
  118. <CheckBoxLineComponent label="Textures" isSelected={() => scene.texturesEnabled} onSelect={() => scene.texturesEnabled = !scene.texturesEnabled} />
  119. <CheckBoxLineComponent label="Procedural textures" isSelected={() => scene.proceduralTexturesEnabled} onSelect={() => scene.proceduralTexturesEnabled = !scene.proceduralTexturesEnabled} />
  120. <CheckBoxLineComponent label="Render targets" isSelected={() => scene.renderTargetsEnabled} onSelect={() => scene.renderTargetsEnabled = !scene.renderTargetsEnabled} />
  121. <CheckBoxLineComponent label="Shadows" isSelected={() => scene.shadowsEnabled} onSelect={() => scene.shadowsEnabled = !scene.shadowsEnabled} />
  122. <CheckBoxLineComponent label="Skeletons" isSelected={() => scene.skeletonsEnabled} onSelect={() => scene.skeletonsEnabled = !scene.skeletonsEnabled} />
  123. <CheckBoxLineComponent label="Sprites" isSelected={() => scene.spritesEnabled} onSelect={() => scene.spritesEnabled = !scene.spritesEnabled} />
  124. </LineContainerComponent>
  125. </div>
  126. );
  127. }
  128. }