-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add useLoader hook (contribution from Hookex react-babylonjs fork)
move customComponents to hostComponents (except for Skybox). Add that texture can be assigned to a model (will need to do so for materials as well).
- Loading branch information
Showing
29 changed files
with
304 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,3 @@ | ||
export { | ||
default as AdvancedDynamicTextureLifecycleListener, ADTFullscreenUILifecycleListener | ||
} from "./AdvancedDynamicTextureLifecycleListener" | ||
export {default as CameraLifecycleListener} from "./CameraLifecycleListener" | ||
export {default as EnvironmentHelperLifecycleListener} from "./EnvironmentHelperLifecycleListener" | ||
export {default as GUI2DControlLifecycleListener} from "./GUI2DControlLifecycleListener" | ||
export {default as GUI3DControlLifecycleListener} from "./GUI3DControlLifecycleListener" | ||
export {default as GUI3DManagerLifecycleListener} from "./GUI3DManagerLifecycleListener" | ||
export {default as MaterialsLifecycleListener} from "./MaterialsLifecycleListener" | ||
export {default as ModelLifecycleListener} from "./ModelLifecycleListener" | ||
export {default as PhysicsImpostorLifecycleListener} from "./PhysicsImpostorLifecycleListener" | ||
export {default as ShadowGeneratorLifecycleListener} from "./ShadowGeneratorLifecycleListener" | ||
// These are class and functional React components (not "host components" like <standardMaterial> or <box>) | ||
export {default as ModelLifecycleListener} from "../customHosts/ModelLifecycleListener" | ||
export {default as Skybox} from "./Skybox" | ||
export {default as TargetPropsHandler} from "./TargetPropsHandler" | ||
export {default as TexturesLifecycleListener} from "./TexturesLifecycleListener" | ||
export {default as VRExperienceHelperLifecycleListener} from "./VRExperienceHelperLifecycleListener" | ||
export {default as NodeLifecycleListener} from "./NodeLifecycleListener"; | ||
export {default as BehaviorLifecycleListener} from "./BehaviorsLifecycleListener"; |
216 changes: 108 additions & 108 deletions
216
...dvancedDynamicTextureLifecycleListener.ts → ...dvancedDynamicTextureLifecycleListener.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,108 +1,108 @@ | ||
import { CreatedInstance } from "../CreatedInstance" | ||
import { LifecycleListener } from "../LifecycleListener" | ||
import { Color3, Scene, StandardMaterial, Mesh } from "@babylonjs/core" | ||
import { FiberAdvancedDynamicTextureProps } from "../generatedProps" | ||
import { AdvancedDynamicTexture } from "@babylonjs/gui/2D/advancedDynamicTexture"; | ||
|
||
|
||
|
||
export default class AdvancedDynamicTextureLifecycleListener implements LifecycleListener<AdvancedDynamicTexture> { | ||
protected props: FiberAdvancedDynamicTextureProps; | ||
protected scene: Scene | ||
|
||
constructor(scene: Scene, props: any) { | ||
this.scene = scene | ||
this.props = props | ||
} | ||
|
||
onParented(parent: CreatedInstance<any>, child: CreatedInstance<any>): any { /* empty */} | ||
|
||
onChildAdded(child: CreatedInstance<any>, parent: CreatedInstance<any>): any { /* empty */} | ||
|
||
onMount(instance: CreatedInstance<AdvancedDynamicTexture>): void { | ||
this.addControls(instance) | ||
|
||
if (instance.customProps.createForParentMesh) { | ||
// console.log('for parent mesh', instance.parent ? instance.parent.babylonJsObject : 'error: no parent object') | ||
|
||
let mesh: Mesh = instance.parent!.hostInstance // should crawl parent hierarchy for a mesh | ||
// console.error('we will be attaching the mesh:', mesh.name, mesh); | ||
|
||
const material = new StandardMaterial("AdvancedDynamicTextureMaterial", mesh.getScene()) | ||
material.backFaceCulling = false | ||
material.diffuseColor = Color3.Black() | ||
material.specularColor = Color3.Black() | ||
|
||
if(instance.hostInstance === undefined) { | ||
console.error('missing instance') | ||
} else { | ||
if (this.props.hasAlpha) { | ||
material.diffuseTexture = instance.hostInstance | ||
material.emissiveTexture = instance.hostInstance | ||
instance.hostInstance.hasAlpha = true | ||
} else { | ||
material.emissiveTexture = instance.hostInstance | ||
material.opacityTexture = instance.hostInstance | ||
} | ||
} | ||
|
||
mesh.material = material | ||
|
||
// set to true unless explicitly not wanted. | ||
// connects the texture to a hosting mesh to enable interactions | ||
let supportPointerMove = (this.props as any).supportPointerMove !== false ? true : false | ||
|
||
instance.hostInstance!.attachToMesh(mesh, supportPointerMove) | ||
} | ||
} | ||
|
||
addControls(instance: CreatedInstance<AdvancedDynamicTexture>) { | ||
// When there is a panel, it must be added before the children. Otherwise there is no UtilityLayer to attach to. | ||
// This project before 'react-reconciler' was added from parent up the tree. 'react-reconciler' wants to do the opposite. | ||
instance.children.forEach(child => { | ||
if (child.metadata.isGUI2DControl === true) { | ||
instance.hostInstance!.addControl(child.hostInstance) | ||
child.state = { added: true } | ||
} | ||
}) | ||
|
||
if (instance.customProps.connectControlNames !== undefined && Array.isArray(instance.customProps.connectControlNames)) { | ||
let controlNames: string[] = instance.customProps.connectControlNames | ||
let root = instance | ||
while (root.parent !== null) { | ||
root = root.parent | ||
} | ||
this.connect( | ||
instance, | ||
root, | ||
controlNames | ||
) | ||
} | ||
|
||
instance.children.forEach(child => { | ||
this.addControls(child) | ||
}) | ||
} | ||
|
||
connect(keyboard: CreatedInstance<any>, searchInstance: CreatedInstance<any>, controlNames: string[]) { | ||
if (searchInstance.metadata.isGUI2DControl && searchInstance.hostInstance && controlNames.indexOf(searchInstance.hostInstance.name) !== -1) { | ||
// console.log(keyboard.hostInstance, '.connect(->', searchInstance.hostInstance) | ||
keyboard.hostInstance.connect(searchInstance.hostInstance) | ||
} | ||
|
||
searchInstance.children.forEach(child => | ||
this.connect( | ||
keyboard, | ||
child, | ||
controlNames | ||
) | ||
) | ||
} | ||
|
||
onUnmount(): void {/* empty */} | ||
} | ||
|
||
/** | ||
* This is attached by convention in react-reconciler HostConfig. | ||
*/ | ||
export class ADTFullscreenUILifecycleListener extends AdvancedDynamicTextureLifecycleListener {/* empty */} | ||
import { CreatedInstance } from "../CreatedInstance" | ||
import { LifecycleListener } from "../LifecycleListener" | ||
import { Color3, Scene, StandardMaterial, Mesh } from "@babylonjs/core" | ||
import { FiberAdvancedDynamicTextureProps } from "../generatedProps" | ||
import { AdvancedDynamicTexture } from "@babylonjs/gui/2D/advancedDynamicTexture"; | ||
|
||
|
||
|
||
export default class AdvancedDynamicTextureLifecycleListener implements LifecycleListener<AdvancedDynamicTexture> { | ||
protected props: FiberAdvancedDynamicTextureProps; | ||
protected scene: Scene | ||
|
||
constructor(scene: Scene, props: any) { | ||
this.scene = scene | ||
this.props = props | ||
} | ||
|
||
onParented(parent: CreatedInstance<any>, child: CreatedInstance<any>): any { /* empty */} | ||
|
||
onChildAdded(child: CreatedInstance<any>, parent: CreatedInstance<any>): any { /* empty */} | ||
|
||
onMount(instance: CreatedInstance<AdvancedDynamicTexture>): void { | ||
this.addControls(instance) | ||
|
||
if (instance.customProps.createForParentMesh) { | ||
// console.log('for parent mesh', instance.parent ? instance.parent.babylonJsObject : 'error: no parent object') | ||
|
||
let mesh: Mesh = instance.parent!.hostInstance // should crawl parent hierarchy for a mesh | ||
// console.error('we will be attaching the mesh:', mesh.name, mesh); | ||
|
||
const material = new StandardMaterial("AdvancedDynamicTextureMaterial", mesh.getScene()) | ||
material.backFaceCulling = false | ||
material.diffuseColor = Color3.Black() | ||
material.specularColor = Color3.Black() | ||
|
||
if(instance.hostInstance === undefined) { | ||
console.error('missing instance') | ||
} else { | ||
if (this.props.hasAlpha) { | ||
material.diffuseTexture = instance.hostInstance | ||
material.emissiveTexture = instance.hostInstance | ||
instance.hostInstance.hasAlpha = true | ||
} else { | ||
material.emissiveTexture = instance.hostInstance | ||
material.opacityTexture = instance.hostInstance | ||
} | ||
} | ||
|
||
mesh.material = material | ||
|
||
// set to true unless explicitly not wanted. | ||
// connects the texture to a hosting mesh to enable interactions | ||
let supportPointerMove = (this.props as any).supportPointerMove !== false ? true : false | ||
|
||
instance.hostInstance!.attachToMesh(mesh, supportPointerMove) | ||
} | ||
} | ||
|
||
addControls(instance: CreatedInstance<AdvancedDynamicTexture>) { | ||
// When there is a panel, it must be added before the children. Otherwise there is no UtilityLayer to attach to. | ||
// This project before 'react-reconciler' was added from parent up the tree. 'react-reconciler' wants to do the opposite. | ||
instance.children.forEach(child => { | ||
if (child.metadata.isGUI2DControl === true) { | ||
instance.hostInstance!.addControl(child.hostInstance) | ||
child.state = { added: true } | ||
} | ||
}) | ||
|
||
if (instance.customProps.connectControlNames !== undefined && Array.isArray(instance.customProps.connectControlNames)) { | ||
let controlNames: string[] = instance.customProps.connectControlNames | ||
let root = instance | ||
while (root.parent !== null) { | ||
root = root.parent | ||
} | ||
this.connect( | ||
instance, | ||
root, | ||
controlNames | ||
) | ||
} | ||
|
||
instance.children.forEach(child => { | ||
this.addControls(child) | ||
}) | ||
} | ||
|
||
connect(keyboard: CreatedInstance<any>, searchInstance: CreatedInstance<any>, controlNames: string[]) { | ||
if (searchInstance.metadata.isGUI2DControl && searchInstance.hostInstance && controlNames.indexOf(searchInstance.hostInstance.name) !== -1) { | ||
// console.log(keyboard.hostInstance, '.connect(->', searchInstance.hostInstance) | ||
keyboard.hostInstance.connect(searchInstance.hostInstance) | ||
} | ||
|
||
searchInstance.children.forEach(child => | ||
this.connect( | ||
keyboard, | ||
child, | ||
controlNames | ||
) | ||
) | ||
} | ||
|
||
onUnmount(): void {/* empty */} | ||
} | ||
|
||
/** | ||
* This is attached by convention in react-reconciler HostConfig. | ||
*/ | ||
export class ADTFullscreenUILifecycleListener extends AdvancedDynamicTextureLifecycleListener {/* empty */} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,25 @@ | ||
// With respect to renderers there are two types of react components: | ||
// Composite components ie: <MyComponent> Regular react components that use host components. | ||
// Host Components: Platform-specific components used in lower-case (ie: <standardMaterial> or <box>) | ||
export { | ||
default as AdvancedDynamicTextureLifecycleListener, ADTFullscreenUILifecycleListener | ||
} from "./AdvancedDynamicTextureLifecycleListener" | ||
export { default as CameraLifecycleListener } from "./CameraLifecycleListener" | ||
export { default as EnvironmentHelperLifecycleListener } from "./EnvironmentHelperLifecycleListener" | ||
export { default as GUI2DControlLifecycleListener } from "./GUI2DControlLifecycleListener" | ||
export { default as GUI3DControlLifecycleListener } from "./GUI3DControlLifecycleListener" | ||
export { default as GUI3DManagerLifecycleListener } from "./GUI3DManagerLifecycleListener" | ||
export { default as MaterialsLifecycleListener } from "./MaterialsLifecycleListener" | ||
export { default as ModelLifecycleListener } from "./ModelLifecycleListener" | ||
export { default as PhysicsImpostorLifecycleListener } from "./PhysicsImpostorLifecycleListener" | ||
export { default as ShadowGeneratorLifecycleListener } from "./ShadowGeneratorLifecycleListener" | ||
export { default as TargetPropsHandler } from "./TargetPropsHandler" | ||
export { default as TexturesLifecycleListener } from "./TexturesLifecycleListener" | ||
export { default as VRExperienceHelperLifecycleListener } from "./VRExperienceHelperLifecycleListener" | ||
export { default as NodeLifecycleListener } from "./NodeLifecycleListener"; | ||
export { default as BehaviorLifecycleListener } from "./BehaviorsLifecycleListener"; | ||
|
||
// These are only used by the reconciler. We export them as strings (as we do for all generated code as well) | ||
// For declaring your own custom components externally you just need the 'string' version from /exportedCustomComponents | ||
export { default as HostWithEventsFiber } from "./hostWithEventsFiber" | ||
|
||
export const HostWithEvents: string = "HostWithEvents" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.