-
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.
* feat[behavior]: add feature and story Co-authored-by: huxiaohui <huxiaohui@megvii.com>
- Loading branch information
Showing
10 changed files
with
1,484 additions
and
102 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { CreatedInstance } from "../CreatedInstance" | ||
import { LifecycleListener } from "../LifecycleListener" | ||
import { Node } from '@babylonjs/core/node' | ||
import {Behavior, PointerDragBehavior} from "@babylonjs/core"; | ||
|
||
type behaviors = Behavior<PointerDragBehavior>; | ||
|
||
export default class BehaviorLifecycleListener implements LifecycleListener<behaviors> { | ||
onParented(parent: CreatedInstance<any>, child: CreatedInstance<any>) { | ||
if (parent.metadata.isNode && child.metadata.isBehavior) { | ||
// TODO: consider add option for setParent(), which parents and maintains mesh pos/rot in world space | ||
// child.hostInstance.setParent(parent.hostInstance) | ||
parent.hostInstance.addBehavior(child.hostInstance) | ||
} | ||
} | ||
onChildAdded(parent: CreatedInstance<any>, child: CreatedInstance<any>) {/* empty */} | ||
onMount(instance: CreatedInstance<behaviors>) {/* empty */} | ||
onUnmount(): void {/* empty */} | ||
} | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { CreatedInstance } from "../CreatedInstance" | ||
import { LifecycleListener } from "../LifecycleListener" | ||
import { Mesh } from '@babylonjs/core/Meshes' | ||
import {EffectLayer} from "@babylonjs/core"; | ||
|
||
export default class EffectLayerLifecycleListener implements LifecycleListener<EffectLayer> { | ||
onParented(parent: CreatedInstance<any>, child: CreatedInstance<any>) {/* empty */} | ||
onChildAdded(parent: CreatedInstance<any>, child: CreatedInstance<any>) {/* empty */} | ||
onMount(instance: CreatedInstance<EffectLayer>) {/* empty */} | ||
onUnmount(): void {/* empty */} | ||
} |
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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
stories/babylonjs/8-behaviors/pointerDragBehavior.stories.js
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from 'react' | ||
import {storiesOf} from '@storybook/react' | ||
import {Engine, Scene} from '../../../dist/react-babylonjs.es5' | ||
import {Vector3} from '@babylonjs/core/Maths/math' | ||
import '../../style.css' | ||
|
||
/** | ||
* official demo: | ||
* https://www.babylonjs-playground.com/#YEZPVT | ||
* | ||
* TODO: camera autoAttaching? | ||
*/ | ||
|
||
function WithPointerDragBehavior() { | ||
return ( | ||
<> | ||
<sphere name='sphere1' diameter={2} segments={16} position={new Vector3(0, 1, 0)}> | ||
<pointerDragBehavior dragAxis={new Vector3(1, 0, 0)} | ||
useObjectOrientationForDragging={true} | ||
onDragStartObservable={_ => console.log('dragStart')} | ||
onDragObservable={_ => console.log('drag')} | ||
onDragEndObservable={_ => console.log('dragEnd')}/> | ||
</sphere> | ||
<ground name='ground1' width={6} height={6} subdivisions={2}/> | ||
</> | ||
) | ||
} | ||
|
||
export default storiesOf('Behaviors', module) | ||
.add('Pointer drag behavior', () => ( | ||
<div style={{flex: 1, display: 'flex'}}> | ||
<Engine antialias adaptToDeviceRatio canvasId='babylonJS'> | ||
<Scene> | ||
<freeCamera name='camera1' | ||
position={new Vector3(0, 5, -10)} | ||
setTarget={[Vector3.Zero()]}/> | ||
<hemisphericLight name='light1' intensity={0.7} direction={Vector3.Up()}/> | ||
<WithPointerDragBehavior/> | ||
</Scene> | ||
</Engine> | ||
</div> | ||
) | ||
) |
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