forked from playcanvas/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.js
More file actions
221 lines (207 loc) · 9.83 KB
/
Copy pathapplication.js
File metadata and controls
221 lines (207 loc) · 9.83 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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import { platform } from '../core/platform.js';
import { WebglGraphicsDevice } from '../platform/graphics/webgl/webgl-graphics-device.js';
import { SoundManager } from '../platform/sound/manager.js';
import { Lightmapper } from './lightmapper/lightmapper.js';
import { BatchManager } from '../scene/batching/batch-manager.js';
import { AppBase } from './app-base.js';
import { AppOptions } from './app-options.js';
import { AnimationComponentSystem } from './components/animation/system.js';
import { AnimComponentSystem } from './components/anim/system.js';
import { AudioListenerComponentSystem } from './components/audio-listener/system.js';
import { ButtonComponentSystem } from './components/button/system.js';
import { CollisionComponentSystem } from './components/collision/system.js';
import { ElementComponentSystem } from './components/element/system.js';
import { JointComponentSystem } from './components/joint/system.js';
import { LayoutChildComponentSystem } from './components/layout-child/system.js';
import { LayoutGroupComponentSystem } from './components/layout-group/system.js';
import { ModelComponentSystem } from './components/model/system.js';
import { ParticleSystemComponentSystem } from './components/particle-system/system.js';
import { RenderComponentSystem } from './components/render/system.js';
import { RigidBodyComponentSystem } from './components/rigid-body/system.js';
import { ScreenComponentSystem } from './components/screen/system.js';
import { ScrollViewComponentSystem } from './components/scroll-view/system.js';
import { ScrollbarComponentSystem } from './components/scrollbar/system.js';
import { SoundComponentSystem } from './components/sound/system.js';
import { SpriteComponentSystem } from './components/sprite/system.js';
import { ZoneComponentSystem } from './components/zone/system.js';
import { CameraComponentSystem } from './components/camera/system.js';
import { LightComponentSystem } from './components/light/system.js';
import { ScriptComponentSystem } from './components/script/system.js';
import { GSplatComponentSystem } from './components/gsplat/system.js';
import { RenderHandler } from './handlers/render.js';
import { AnimationHandler } from './handlers/animation.js';
import { AnimClipHandler } from './handlers/anim-clip.js';
import { AnimStateGraphHandler } from './handlers/anim-state-graph.js';
import { AudioHandler } from './handlers/audio.js';
import { BinaryHandler } from './handlers/binary.js';
import { ContainerHandler } from './handlers/container.js';
import { CssHandler } from './handlers/css.js';
import { CubemapHandler } from './handlers/cubemap.js';
import { FolderHandler } from './handlers/folder.js';
import { FontHandler } from './handlers/font.js';
import { GSplatHandler } from './handlers/gsplat.js';
import { HierarchyHandler } from './handlers/hierarchy.js';
import { HtmlHandler } from './handlers/html.js';
import { JsonHandler } from './handlers/json.js';
import { MaterialHandler } from './handlers/material.js';
import { ModelHandler } from './handlers/model.js';
import { SceneHandler } from './handlers/scene.js';
import { ScriptHandler } from './handlers/script.js';
import { ShaderHandler } from './handlers/shader.js';
import { SpriteHandler } from './handlers/sprite.js';
import { TemplateHandler } from './handlers/template.js';
import { TextHandler } from './handlers/text.js';
import { TextureAtlasHandler } from './handlers/texture-atlas.js';
import { TextureHandler } from './handlers/texture.js';
import { XrManager } from './xr/xr-manager.js';
/**
* @import { ElementInput } from './input/element-input.js'
* @import { GamePads } from '../platform/input/game-pads.js'
* @import { GraphicsDevice } from '../platform/graphics/graphics-device.js'
* @import { Keyboard } from '../platform/input/keyboard.js'
* @import { Mouse } from '../platform/input/mouse.js'
* @import { TouchDevice } from '../platform/input/touch-device.js'
*/
/**
* Application is a subclass of {@link AppBase}, which represents the base functionality for all
* PlayCanvas applications. It acts as a convenience class by internally registering all
* {@link ComponentSystem}s and {@link ResourceHandler}s implemented in the PlayCanvas Engine. This
* makes app setup simple but results in the full engine being included when bundling your
* application.
*/
class Application extends AppBase {
/**
* Create a new Application instance.
*
* Automatically registers these component systems with the application's component system registry:
*
* - anim ({@link AnimComponentSystem})
* - animation ({@link AnimationComponentSystem})
* - audiolistener ({@link AudioListenerComponentSystem})
* - button ({@link ButtonComponentSystem})
* - camera ({@link CameraComponentSystem})
* - collision ({@link CollisionComponentSystem})
* - element ({@link ElementComponentSystem})
* - layoutchild ({@link LayoutChildComponentSystem})
* - layoutgroup ({@link LayoutGroupComponentSystem})
* - light ({@link LightComponentSystem})
* - model ({@link ModelComponentSystem})
* - particlesystem ({@link ParticleSystemComponentSystem})
* - rigidbody ({@link RigidBodyComponentSystem})
* - render ({@link RenderComponentSystem})
* - screen ({@link ScreenComponentSystem})
* - script ({@link ScriptComponentSystem})
* - scrollbar ({@link ScrollbarComponentSystem})
* - scrollview ({@link ScrollViewComponentSystem})
* - sound ({@link SoundComponentSystem})
* - sprite ({@link SpriteComponentSystem})
*
* @param {HTMLCanvasElement | OffscreenCanvas} canvas - The canvas element.
* @param {object} [options] - The options object to configure the Application.
* @param {ElementInput} [options.elementInput] - Input handler for {@link ElementComponent}s.
* @param {Keyboard} [options.keyboard] - Keyboard handler for input.
* @param {Mouse} [options.mouse] - Mouse handler for input.
* @param {TouchDevice} [options.touch] - TouchDevice handler for input.
* @param {GamePads} [options.gamepads] - Gamepad handler for input.
* @param {string} [options.scriptPrefix] - Prefix to apply to script urls before loading.
* @param {string} [options.assetPrefix] - Prefix to apply to asset urls before loading.
* @param {GraphicsDevice} [options.graphicsDevice] - The graphics device used by the
* application. If not provided, a WebGl graphics device will be created.
* @param {object} [options.graphicsDeviceOptions] - Options object that is passed into the
* {@link GraphicsDevice} constructor.
* @param {string[]} [options.scriptsOrder] - Scripts in order of loading first.
* @example
* // Engine-only example: create the application manually
* const app = new pc.Application(canvas, options);
*
* // Start the application's main loop
* app.start();
*/
constructor(canvas, options = {}) {
super(canvas);
const appOptions = new AppOptions();
appOptions.graphicsDevice = options.graphicsDevice ?? this.createDevice(canvas, options);
this.addComponentSystems(appOptions);
this.addResourceHandles(appOptions);
appOptions.elementInput = options.elementInput;
appOptions.keyboard = options.keyboard;
appOptions.mouse = options.mouse;
appOptions.touch = options.touch;
appOptions.gamepads = options.gamepads;
appOptions.scriptPrefix = options.scriptPrefix;
appOptions.assetPrefix = options.assetPrefix;
appOptions.scriptsOrder = options.scriptsOrder;
appOptions.soundManager = new SoundManager();
appOptions.lightmapper = Lightmapper;
appOptions.batchManager = BatchManager;
appOptions.xr = XrManager;
this.init(appOptions);
}
createDevice(canvas, options) {
if (!options.graphicsDeviceOptions) {
options.graphicsDeviceOptions = { };
}
if (platform.browser && !!navigator.xr) {
options.graphicsDeviceOptions.xrCompatible = true;
}
options.graphicsDeviceOptions.alpha = options.graphicsDeviceOptions.alpha || false;
return new WebglGraphicsDevice(canvas, options.graphicsDeviceOptions);
}
addComponentSystems(appOptions) {
appOptions.componentSystems = [
RigidBodyComponentSystem,
CollisionComponentSystem,
JointComponentSystem,
AnimationComponentSystem,
AnimComponentSystem,
ModelComponentSystem,
RenderComponentSystem,
CameraComponentSystem,
LightComponentSystem,
ScriptComponentSystem,
SoundComponentSystem,
AudioListenerComponentSystem,
ParticleSystemComponentSystem,
ScreenComponentSystem,
ElementComponentSystem,
ButtonComponentSystem,
ScrollViewComponentSystem,
ScrollbarComponentSystem,
SpriteComponentSystem,
LayoutGroupComponentSystem,
LayoutChildComponentSystem,
ZoneComponentSystem,
GSplatComponentSystem
];
}
addResourceHandles(appOptions) {
appOptions.resourceHandlers = [
RenderHandler,
AnimationHandler,
AnimClipHandler,
AnimStateGraphHandler,
ModelHandler,
MaterialHandler,
TextureHandler,
TextHandler,
JsonHandler,
AudioHandler,
ScriptHandler,
SceneHandler,
CubemapHandler,
HtmlHandler,
CssHandler,
ShaderHandler,
HierarchyHandler,
FolderHandler,
FontHandler,
BinaryHandler,
TextureAtlasHandler,
SpriteHandler,
TemplateHandler,
ContainerHandler,
GSplatHandler
];
}
}
export { Application };