Skip to content

Commit

Permalink
add Gizmo and UtilityLayerRenderer support
Browse files Browse the repository at this point in the history
  • Loading branch information
brianzinn committed Aug 12, 2021
1 parent 19e9683 commit 6e22c87
Show file tree
Hide file tree
Showing 9 changed files with 1,159 additions and 7 deletions.
7 changes: 4 additions & 3 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ If you want to declaratively use something not listed here create an issue :) S
5. **Lights** - directionalLight, hemisphericLight, light, pointLight, shadowLight, spotLight

6. **Textures** - advancedDynamicTexture, baseTexture, colorGradingTexture, cubeTexture, customProceduralTexture, dynamicTexture, equiRectangularCubeTexture, hdrCubeTexture, htmlElementTexture, mirrorTexture, multiRenderTarget, multiviewRenderTarget, noiseProceduralTexture, proceduralTexture, rawCubeTexture, rawTexture, rawTexture2DArray, rawTexture3D, refractionTexture, renderTargetTexture, texture, videoTexture
6. **Textures** - advancedDynamicTexture, baseTexture, colorGradingTexture, cubeTexture, customProceduralTexture, dynamicTexture, equiRectangularCubeTexture, hdrCubeTexture, htmlElementTexture, mirrorTexture, multiRenderTarget, multiviewRenderTarget, noiseProceduralTexture, proceduralTexture, rawCubeTexture, rawTexture, rawTexture2DArray, rawTexture3D, refractionTexture, renderTargetTexture, texture, thinTexture, videoTexture

7. **EffectLayers** - effectLayer, glowLayer, highlightLayer

Expand All @@ -33,10 +33,11 @@ If you want to declaratively use something not listed here create an issue :) S
9. **PostProcessRenderPipelines**: defaultRenderingPipeline, lensRenderingPipeline, postProcessRenderPipeline, ssao2RenderingPipeline, ssaoRenderingPipeline, standardRenderingPipeline

10. **PostProcesss** anaglyphPostProcess, blackAndWhitePostProcess, bloomMergePostProcess, blurPostProcess, chromaticAberrationPostProcess, circleOfConfusionPostProcess, colorCorrectionPostProcess, convolutionPostProcess, depthOfFieldBlurPostProcess, depthOfFieldMergePostProcess, displayPassPostProcess, extractHighlightsPostProcess, filterPostProcess, fxaaPostProcess, grainPostProcess, highlightsPostProcess, imageProcessingPostProcess, motionBlurPostProcess, passCubePostProcess, passPostProcess, postProcess, refractionPostProcess, screenSpaceCurvaturePostProcess, screenSpaceReflectionPostProcess, sharpenPostProcess, stereoscopicInterlacePostProcess, stereoscopicInterlacePostProcessI, subSurfaceScatteringPostProcess, tonemapPostProcess, volumetricLightScatteringPostProcess, vrDistortionCorrectionPostProcess, vrMultiviewToSingleviewPostProcess

> note: for `PostProcess` (and `PostProcessRenderPipeline`) the `ImageProcessingConfiguration` and `PrePassConfiguration` properties can be declared with `assignFrom`.
11. **Others** - adtForMesh, adtFullScreenUi, environmentHelper, physicsImpostor, pointsCloudSystem, shadowGenerator / cascadedShadowGenerator, viewport, vrExperienceHelper
11. **Gizmo** axisDragGizmo, axisScaleGizmo, boundingBoxGizmo, cameraGizmo, gizmo, lightGizmo, planeDragGizmo, planeRotationGizmo, positionGizmo, rotationGizmo, scaleGizmo

12. **Others** - adtForMesh, adtForMeshTexture, adtFullScreenUi, environmentHelper, physicsImpostor, pointsCloudSystem, shadowGenerator / cascadedShadowGenerator, utilityLayerRenderer, viewport, vrExperienceHelper

## @babylonjs/gui
1. GUI3DManager
Expand Down
2 changes: 2 additions & 0 deletions src/CreatedInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export interface InstanceMetadataParameter {
isGlowLayer?: boolean;
isBehavior?: boolean;
isShadowGenerator?: boolean
isUtilityLayerRenderer?: boolean
isGizmo?: boolean
}

export interface CreatedInstanceMetadata extends InstanceMetadataParameter {
Expand Down
4 changes: 3 additions & 1 deletion src/ReactBabylonJSHostConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,9 @@ const ReactBabylonJSHostConfig: HostConfig<

// Consider these being dynamically attached to a list, much like PropsHandlers<T>
let metadataLifecycleListenerName: string | undefined;
if (metadata.isMaterial === true) {
if (metadata.isGizmo === true) {
metadataLifecycleListenerName = 'Gizmo';
} else if (metadata.isMaterial === true) {
metadataLifecycleListenerName = 'Materials';
} else if (metadata.isTexture === true) { // must be before .isGUI2DControl, since ADT/FullScreenUI declare both.
metadataLifecycleListenerName = 'Textures';
Expand Down
36 changes: 36 additions & 0 deletions src/customHosts/GizmoLifecycleListener.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Gizmo } from '@babylonjs/core/Gizmos/gizmo';
import { Texture } from '@babylonjs/core/Materials/Textures/texture.js';

import { CreatedInstance } from '../CreatedInstance';
import BaseLifecycleListener from './BaseLifecycleListener';

export default class GizmoLifecycleListener extends BaseLifecycleListener<Texture, any> {
onMount(instance: CreatedInstance<Texture>) {
const gizmo = instance.hostInstance as any as Gizmo;

let tmp: CreatedInstance<any> | null = instance.parent;
let foundUtilityLayerRender = false;
while (tmp !== null) {
if (tmp.metadata && tmp.metadata.isUtilityLayerRenderer === true) {
gizmo.gizmoLayer = tmp.hostInstance;
foundUtilityLayerRender = true;
break;
}
tmp = tmp.parent;
}

if (foundUtilityLayerRender !== true) {
console.error('utility layer not found (not attaching to mesh)');
} else {
// TODO: determine if we are searching for a Mesh or Node to attach to.
let tmp: CreatedInstance<any> | null = instance.parent;
while (tmp !== null) {
if (tmp.metadata && tmp.metadata.isMesh === true) {
gizmo.attachedMesh = tmp.hostInstance;
break;
}
tmp = tmp.parent;
}
}
}
}
3 changes: 2 additions & 1 deletion src/customHosts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ export { default as BehaviorLifecycleListener } from './BehaviorsLifecycleListen
export { default as FallbackLifecycleListener } from './FallbackLifecycleListener';
export { default as ViewportLifecycleListener } from './ViewportLifecycleListener';
export { default as EngineViewLifecycleListener} from './EngineViewLifecycleListener';
export { default as AbstractMeshLifecycleListener} from './AbstractMeshLifecycleListener';
export { default as AbstractMeshLifecycleListener} from './AbstractMeshLifecycleListener';
export { default as GizmoLifecycleListener} from './GizmoLifecycleListener';
Loading

0 comments on commit 6e22c87

Please sign in to comment.