-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path22-BeforeRender.sb
More file actions
98 lines (74 loc) · 2.32 KB
/
22-BeforeRender.sb
File metadata and controls
98 lines (74 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
;Babylon.sbi - BeforeRender()
EnableExplicit
IncludeFile "babylon/babylon.sbi"
Enumeration
#mf
#mfRender
EndEnumeration
Global Scene, Camera, Light, Ground, GroundTex, GroundMat, Cylinder, Bloc, BlocMat, ShadowGenerator
Declare LoadGame()
Declare BlocAnim()
Declare RenderGame()
UseModule BJS
OpenWindow(#mf, 0, 0, 800, 600, "BeforeRender() process", #PB_Window_ScreenCentered)
CanvasGadget(#mfRender, 0, 0, 900, 600, #PB_Canvas_Transparent)
SetEnginePath("sbbjs")
InitEngine(@LoadGame(), #mfRender)
Procedure LoadGame()
Scene = CreateScene()
If Scene
;Camera & Light
Camera = CreateCamera("camera", 0, 6, 10, #BJS_ArcRotate)
CameraLookAt(Camera, 0, 3, 0)
CreateLight("light", 0, 5, 10, 1)
Light = CreateLight("Point", 0, 10, -10, 0.8, #BJS_Point)
;Material
GroundTex = LoadTexture("data/textures/grass1.jpg")
GroundMat = CreateMaterial("grass")
SetMaterialTexture(GroundMat, #BJS_Diffuse, GroundTex)
ScaleMaterial(GroundMat, 5, 5)
BlocMat = CreateMaterial("bloc coloe")
SetMaterialColor(BlocMat, #BJS_Diffuse, RGB(255, 0, 0))
;Mesh
Ground = CreateGround("ground", 40, 40)
SetMeshMaterial(Ground, GroundMat)
Cylinder = CreateCylinder("cylinder", 5, 0.5, 0.5)
MoveMesh(Cylinder, 0, 2.5, -10)
Bloc = CreateBox("bloc", 2, 2, 2)
SetMeshMaterial(Bloc, BlocMat)
MoveMesh(Bloc, 0, 4, -10)
;Shadow
ShadowGenerator = InitShadow(Light)
ShadowEmitter(ShadowGenerator, Bloc)
RenderShadows(Ground)
;BeforeRender() function can be used to automate a task.
BeforeRender(@BlocAnim())
RenderLoop(@RenderGame())
EndIf
EndProcedure
Procedure BlocAnim()
Static y.f, i.f
If MeshY(Bloc) <= 1
i = -0.5
EndIf
If MeshY(Bloc) >= 4
i = 0.5
EndIf
y - i/10
MoveMesh(Bloc, 0, y, -10)
RotateMesh(Bloc, 0, i, 0, #PB_Relative)
EndProcedure
Procedure RenderGame()
RenderWorld()
EndProcedure
; IDE Options = SpiderBasic 2.20 (Windows - x86)
; CursorPosition = 58
; Folding = -
; WebAppName = Before Render
; HtmlFilename = beforerender.html
; JavaScriptFilename = beforerender.js
; JavaScriptPath = sb
; iOSAppOrientation = 0
; AndroidAppOrientation = 0
; EnableXP
; CompileSourceDirectory