-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path28-Assets Manager.sb
124 lines (98 loc) · 3.71 KB
/
28-Assets Manager.sb
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
;Babylon.sbi - Assets Manager
EnableExplicit
IncludeFile "babylon/babylon.sbi"
Global ShadowGenerator
Declare LoadGame()
Declare onProgress(RemainingCount, TotalCount, Name)
Declare onLoad(Name.s, Element)
Declare onError(Name.s, Message.s)
Declare RenderGame()
UseModule BJS
InitEngine(@LoadGame())
Procedure LoadGame()
Protected Scene, Camera, Light
Scene = CreateScene()
If Scene
;Camera
Camera = CreateCamera("camera", 0, 7, -20, #BJS_ArcRotate)
CameraLookAt(Camera, 0, 3, 0)
;Fog
ClearScene(RGB(0, 0, 0))
Fog(RGB(0, 0, 0), 1, 20, 50)
;Light & Shadow generator
CreateLight("light", 0, 200, 0, 0.1, #BJS_Hemispheric)
Light = CreateLight("point", 100, 150, 0, 1, #BJS_Spot)
ShadowGenerator = InitShadow(Light, 2024)
;Assets Manager : Init
UseAssetsManager(@onProgress())
AssetsManagerColor(RGB(111, 103, 114))
;Assets Manager : Add scene elements
AssetsManagerAdd("tvled", "data/tvled/tvled.babylon", @onLoad(), @onError())
AssetsManagerAdd("skull", "data/skull/bad-skull.babylon", @onLoad(), @onError())
AssetsManagerAdd("boletus", "data/boletus/boletus.babylon", @onLoad(), @onError())
AssetsManagerAdd("beton", "data/textures/Beton1.png", @OnLoad(), @OnError())
;Assets Manager : Load
AssetsManagerLoad()
RenderLoop(@RenderGame())
EndIf
EndProcedure
Procedure onProgress(RemainingCount, TotalCount, Name)
AssetsManagerPrompt("Loading " + RemainingCount + " / " + TotalCount + " - " + Name)
EndProcedure
Procedure onLoad(Name.s, Element)
Protected Ground, GroundMat, Screen, ScreenMat, ScreenTex, Mesh
Select Name
Case "tvled"
MoveMesh(Element, 6, 5.50, 0)
RotateMesh(Element, 0, 90, 0)
ShadowEmitter(ShadowGenerator, Element)
;Video Screen
Screen = CreatePlane("screen", 16, 8.7)
MoveMesh(Screen, 5, 6.3, 0)
RotateMesh(Screen, 0, -90, 180)
ScreenMat = CreateMaterial("screen")
ScreenTex = LoadVideoTexture("video", "data/video/video3.mp4")
SetMaterialColor(ScreenMat, #BJS_Emissive, RGB(1, 1, 1))
SetMaterialTexture(ScreenMat, #BJS_Diffuse, ScreenTex)
SetMeshMaterial(Screen, ScreenMat)
Case "skull"
ScaleMesh(Element, 0.03, 0.03, 0.03)
RotateMesh(Element, 0, 0, 90)
MoveMesh(Element, -10, 2, 0)
ShadowEmitter(ShadowGenerator, Element)
Case "boletus"
MoveMesh(Element, 0, 0, 15)
RotateMesh(Element, 90, 0, 90)
ScaleMesh(Element, 0.05, 0.05, 0.05)
ShadowEmitter(ShadowGenerator, Element)
Mesh = CloneMesh(Element, "Boletus 1")
MoveMesh(Mesh, -1, 0, 12)
RotateMesh(Mesh, 90, 45, 90)
ScaleMesh(mesh, 0.03, 0.03, 0.03)
ShadowEmitter(ShadowGenerator, Mesh)
Case "beton"
Ground = CreateGround("ground", 100, 100)
GroundMat = CreateMaterial("ground material")
SetMaterialTexture(GroundMat, #BJS_Diffuse, Element)
ScaleMaterial(GroundMat, 8, 8)
SetMeshMaterial(Ground, GroundMat)
RenderShadows(Ground)
EndSelect
EndProcedure
Procedure onError(Name.s, Message.s)
Debug "Error during downloading" + Name + " : " + Message
EndProcedure
Procedure RenderGame()
RenderWorld()
EndProcedure
; IDE Options = SpiderBasic 2.20 (Windows - x86)
; CursorPosition = 35
; Folding = -
; WebAppName = Assets Manager
; HtmlFilename = assetsmanager.html
; JavaScriptFilename = assetsmanager.js
; JavaScriptPath = sb
; iOSAppOrientation = 0
; AndroidAppOrientation = 0
; EnableXP
; CompileSourceDirectory