1
1
import * as React from 'react' ;
2
2
import { RouteComponentProps } from 'react-router-dom' ;
3
3
import { Panel , Well } from 'react-bootstrap' ;
4
- import * as BABYLON from 'babylonjs' ;
5
- import * as GUI from 'babylonjs-gui'
4
+ import { Scene as BabylonScene , Vector3 , HemisphericLight , DirectionalLight , CannonJSPlugin , ArcRotateCamera , MeshBuilder , ShadowGenerator ,
5
+ StandardMaterial , PhysicsImpostor , Mesh , Color3 } from 'babylonjs' ;
6
+ import { AdvancedDynamicTexture , Button } from 'babylonjs-gui'
6
7
7
8
import { Scene as ReactBabylonJsScene , SceneEventArgs } from 'react-babylonjs' ;
8
9
@@ -11,37 +12,37 @@ window.CANNON = CANNON
11
12
12
13
export default class Home extends React . Component < RouteComponentProps < { } > , { } > {
13
14
14
- private scene : BABYLON . Scene ;
15
+ private scene : BabylonScene ;
15
16
16
17
onSceneMount = ( e : SceneEventArgs ) => {
17
18
const { canvas, scene, engine } = e ;
18
19
19
20
this . scene = scene ;
20
21
21
- const gravityVector = new BABYLON . Vector3 ( 0 , - 9.81 , 0 ) ;
22
+ const gravityVector = new Vector3 ( 0 , - 9.81 , 0 ) ;
22
23
23
24
// update /Views/Shared/_Layout.cshtml to include JS for engine of choice.
24
25
//this.scene.enablePhysics(gravityVector, new OimoJSPlugin())
25
- this . scene . enablePhysics ( gravityVector , new BABYLON . CannonJSPlugin ( ) )
26
+ this . scene . enablePhysics ( gravityVector , new CannonJSPlugin ( ) )
26
27
27
- let light = new BABYLON . HemisphericLight ( 'hemi' , new BABYLON . Vector3 ( 0 , - 1 , 0 ) , scene ) ;
28
+ let light = new HemisphericLight ( 'hemi' , new Vector3 ( 0 , - 1 , 0 ) , scene ) ;
28
29
light . intensity = 0.8 ;
29
30
30
- let shadowLight = new BABYLON . DirectionalLight ( 'dir01' , new BABYLON . Vector3 ( 1 , - 0.75 , 1 ) , scene ) ;
31
- shadowLight . position = new BABYLON . Vector3 ( - 40 , 30 , - 40 ) ;
31
+ let shadowLight = new DirectionalLight ( 'dir01' , new Vector3 ( 1 , - 0.75 , 1 ) , scene ) ;
32
+ shadowLight . position = new Vector3 ( - 40 , 30 , - 40 ) ;
32
33
shadowLight . intensity = 0.4 ;
33
34
shadowLight . shadowMinZ = 1 ;
34
35
shadowLight . shadowMaxZ = 2500 ;
35
36
36
- var camera = new BABYLON . ArcRotateCamera ( 'Camera' , Math . PI / - 2 , Math . PI / 4 , 16 , BABYLON . Vector3 . Zero ( ) , scene ) ;
37
+ var camera = new ArcRotateCamera ( 'Camera' , Math . PI / - 2 , Math . PI / 4 , 16 , Vector3 . Zero ( ) , scene ) ;
37
38
// camera.lowerAlphaLimit = -0.0001;
38
39
// camera.upperAlphaLimit = 0.0001;
39
40
camera . lowerRadiusLimit = 8 ; // zoom right into logo
40
41
camera . upperRadiusLimit = 20 ;
41
42
camera . upperBetaLimit = Math . PI / 2 ;
42
43
camera . attachControl ( canvas ) ;
43
44
44
- let shadowGenerator = new BABYLON . ShadowGenerator ( 1024 /* size of shadow map */ , shadowLight ) ;
45
+ let shadowGenerator : ShadowGenerator = new ShadowGenerator ( 1024 /* size of shadow map */ , shadowLight ) ;
45
46
shadowGenerator . bias = 0.001 ;
46
47
shadowGenerator . depthScale = 2500 ;
47
48
@@ -50,10 +51,10 @@ export default class Home extends React.Component<RouteComponentProps<{}>, {}> {
50
51
shadowGenerator . forceBackFacesOnly = true ;
51
52
shadowGenerator . depthScale = 100 ;
52
53
53
- var floor = BABYLON . MeshBuilder . CreateBox ( 'ground' , { width : 10 , height : 1 , depth : 10 } , scene ) ;
54
+ var floor = MeshBuilder . CreateBox ( 'ground' , { width : 10 , height : 1 , depth : 10 } , scene ) ;
54
55
55
- var darkMaterial = new BABYLON . StandardMaterial ( 'Grey' , scene ) ;
56
- darkMaterial . diffuseColor = BABYLON . Color3 . FromInts ( 255 , 255 , 255 ) ; // Color3.FromInts(200, 200, 200)
56
+ var darkMaterial = new StandardMaterial ( 'Grey' , scene ) ;
57
+ darkMaterial . diffuseColor = Color3 . FromInts ( 255 , 255 , 255 ) ; // Color3.FromInts(200, 200, 200)
57
58
floor . material = darkMaterial ;
58
59
floor . receiveShadows = true ;
59
60
@@ -62,32 +63,32 @@ export default class Home extends React.Component<RouteComponentProps<{}>, {}> {
62
63
scene . registerBeforeRender ( ( ) => {
63
64
shadowLight . position . x = Math . cos ( camera . alpha + radiansFromCameraForShadows ) * 40 ;
64
65
shadowLight . position . z = Math . sin ( camera . alpha + radiansFromCameraForShadows ) * 40 ;
65
- shadowLight . setDirectionToTarget ( BABYLON . Vector3 . Zero ( ) ) ;
66
+ shadowLight . setDirectionToTarget ( Vector3 . Zero ( ) ) ;
66
67
} ) ;
67
68
68
- var sphere = BABYLON . Mesh . CreateSphere ( 'sphere' , 10 , 2 , scene , false ) ;
69
+ var sphere = Mesh . CreateSphere ( 'sphere' , 10 , 2 , scene , false ) ;
69
70
sphere . position . y = 5
70
71
71
- shadowGenerator . getShadowMap ( ) . renderList . push ( sphere ) ;
72
+ shadowGenerator . getShadowMap ( ) ! . renderList ! . push ( sphere ) ;
72
73
73
- sphere . physicsImpostor = new BABYLON . PhysicsImpostor ( sphere , BABYLON . PhysicsImpostor . SphereImpostor , { mass : 1 , restitution : 0.9 } , scene ) ;
74
- floor . physicsImpostor = new BABYLON . PhysicsImpostor ( floor , BABYLON . PhysicsImpostor . BoxImpostor , { mass : 0 , restitution : 0.9 } , scene ) ;
74
+ sphere . physicsImpostor = new PhysicsImpostor ( sphere , PhysicsImpostor . SphereImpostor , { mass : 1 , restitution : 0.9 } , scene ) ;
75
+ floor . physicsImpostor = new PhysicsImpostor ( floor , PhysicsImpostor . BoxImpostor , { mass : 0 , restitution : 0.9 } , scene ) ;
75
76
76
77
// GUI
77
- var plane = BABYLON . MeshBuilder . CreatePlane ( "plane" , { size : 2 } , scene ) ;
78
+ var plane = MeshBuilder . CreatePlane ( "plane" , { size : 2 } , scene ) ;
78
79
plane . parent = sphere ;
79
80
plane . position . y = 2 ;
80
81
81
- var advancedTexture = GUI . AdvancedDynamicTexture . CreateForMesh ( plane ) ;
82
+ var advancedTexture = AdvancedDynamicTexture . CreateForMesh ( plane ) ;
82
83
83
- var button1 = GUI . Button . CreateSimpleButton ( "but1" , "Click Me" ) ;
84
+ var button1 = Button . CreateSimpleButton ( "but1" , "Click Me" ) ;
84
85
button1 . width = 1 ;
85
86
button1 . height = 0.4 ;
86
87
button1 . color = "white" ;
87
88
button1 . fontSize = 200 ;
88
89
button1 . background = "green" ;
89
90
button1 . onPointerUpObservable . add ( function ( ) {
90
- sphere . physicsImpostor . applyImpulse ( new BABYLON . Vector3 ( 0 , 10 , 0 ) , sphere . getAbsolutePosition ( ) ) ;
91
+ sphere . physicsImpostor ! . applyImpulse ( new Vector3 ( 0 , 10 , 0 ) , sphere . getAbsolutePosition ( ) ) ;
91
92
} ) ;
92
93
advancedTexture . addControl ( button1 ) ;
93
94
0 commit comments