matrix-engine-wgpu 1.0.6 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codesandbox/tasks.json +46 -0
- package/.devcontainer/devcontainer.json +22 -0
- package/.github/dependabot.yml +12 -0
- package/REFERENCE.md +3 -5
- package/dev.md +460 -0
- package/empty.js +7 -6
- package/examples/games/jamb/jamb.js +1127 -0
- package/examples/load-obj-file.js +65 -28
- package/examples/unlit-textures.js +26 -23
- package/examples.js +35 -3
- package/main.js +442 -48
- package/non-project-files/dev.txt +21 -0
- package/non-project-files/image1.png +0 -0
- package/non-project-files/image6.png +0 -0
- package/package.json +28 -13
- package/public/app.js +11405 -9375
- package/public/css/style.css +371 -110
- package/public/empty.html +1 -1
- package/public/empty.js +9887 -9264
- package/public/examples.html +10 -8
- package/public/examples.js +553 -193
- package/public/index.html +3 -5
- package/public/manifest copy.web +35 -0
- package/public/res/audios/block.mp3 +0 -0
- package/public/res/audios/dice1.mp3 +0 -0
- package/public/res/audios/dice2.mp3 +0 -0
- package/public/res/audios/start.mp3 +0 -0
- package/public/res/meshes/jamb/bg.blend +0 -0
- package/public/res/meshes/jamb/bg.blend1 +0 -0
- package/public/res/meshes/jamb/bg.mtl +12 -0
- package/public/res/meshes/jamb/bg.obj +17 -0
- package/public/res/meshes/jamb/bg.png +0 -0
- package/public/res/meshes/jamb/dice-default.png +0 -0
- package/public/res/meshes/jamb/dice-mark.png +0 -0
- package/public/res/meshes/jamb/dice.mtl +12 -0
- package/public/res/meshes/jamb/dice.obj +40 -0
- package/public/res/meshes/jamb/dice.png +0 -0
- package/public/res/meshes/jamb/jamb-title.mtl +12 -0
- package/public/res/meshes/jamb/jamb-title.obj +26008 -0
- package/public/res/meshes/jamb/jamb.blend +0 -0
- package/public/res/meshes/jamb/jamb.blend1 +0 -0
- package/public/res/meshes/jamb/logo.png +0 -0
- package/public/res/meshes/jamb/nidzaDice.blend +0 -0
- package/public/res/meshes/jamb/nidzaDice.blend1 +0 -0
- package/public/res/meshes/jamb/pile.blend +0 -0
- package/public/res/meshes/jamb/simpleCube.blend +0 -0
- package/public/res/meshes/jamb/simpleCube.blend1 +0 -0
- package/public/res/meshes/jamb/sounds/roll1.wav +0 -0
- package/public/res/meshes/jamb/text.png +0 -0
- package/public/res/multilang/en.json +27 -0
- package/public/res/multilang/sr.json +27 -0
- package/public/test.html +636 -0
- package/public/three-test.js +165 -0
- package/public/worker.html +1 -1
- package/readme.md +189 -115
- package/src/engine/cube.js +10 -1
- package/src/engine/engine.js +1 -5
- package/src/engine/loader-obj.js +9 -6
- package/src/engine/matrix-class.js +237 -204
- package/src/engine/mesh-obj.js +605 -515
- package/src/engine/raycast-test.js +93 -0
- package/src/engine/utils.js +69 -3
- package/src/multilang/lang.js +35 -0
- package/src/physics/matrix-ammo.js +168 -15
- package/src/shaders/fragment.wgsl.js +4 -2
- package/src/shaders/shaders.js +1 -1
- package/src/shaders/vertexShadow.wgsl.js +1 -1
- package/src/sounds/sounds.js +47 -0
- package/src/world.js +311 -248
package/src/world.js
CHANGED
|
@@ -5,255 +5,318 @@ import {ArcballCamera, WASDCamera} from "./engine/engine.js";
|
|
|
5
5
|
import MEMesh from "./engine/mesh.js";
|
|
6
6
|
import MEMeshObj from "./engine/mesh-obj.js";
|
|
7
7
|
import MatrixAmmo from "./physics/matrix-ammo.js";
|
|
8
|
-
import {LOG_WARN, scriptManager} from "./engine/utils.js";
|
|
8
|
+
import {LOG_WARN, genName, mb, scriptManager, urlQuery} from "./engine/utils.js";
|
|
9
|
+
import {MultiLang} from "./multilang/lang.js";
|
|
10
|
+
import {MatrixSounds} from "./sounds/sounds.js";
|
|
9
11
|
|
|
10
12
|
export default class MatrixEngineWGPU {
|
|
11
13
|
|
|
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
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
14
|
+
mainRenderBundle = [];
|
|
15
|
+
rbContainer = [];
|
|
16
|
+
frame = () => {};
|
|
17
|
+
|
|
18
|
+
entityHolder = [];
|
|
19
|
+
|
|
20
|
+
entityArgPass = {
|
|
21
|
+
loadOp: 'clear',
|
|
22
|
+
storeOp: 'store',
|
|
23
|
+
depthLoadOp: 'clear',
|
|
24
|
+
depthStoreOp: 'store'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
matrixAmmo = new MatrixAmmo();
|
|
28
|
+
matrixSounds = new MatrixSounds();
|
|
29
|
+
|
|
30
|
+
// The input handler
|
|
31
|
+
constructor(options, callback) {
|
|
32
|
+
// console.log('typeof options ', typeof options )
|
|
33
|
+
if(typeof options == 'undefined' || typeof options == "function") {
|
|
34
|
+
this.options = {
|
|
35
|
+
useSingleRenderPass: true,
|
|
36
|
+
canvasSize: 'fullscreen',
|
|
37
|
+
mainCameraParams: {
|
|
38
|
+
type: 'WASD',
|
|
39
|
+
responseCoef: 2000
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
callback = options;
|
|
43
|
+
}
|
|
44
|
+
if(typeof options.mainCameraParams === 'undefined') {
|
|
45
|
+
options.mainCameraParams = {
|
|
46
|
+
type: 'WASD',
|
|
47
|
+
responseCoef: 2000
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
this.options = options;
|
|
51
|
+
|
|
52
|
+
this.mainCameraParams = options.mainCameraParams;
|
|
53
|
+
|
|
54
|
+
var canvas = document.createElement('canvas')
|
|
55
|
+
if(this.options.canvasSize == 'fullscreen') {
|
|
56
|
+
canvas.width = window.innerWidth;
|
|
57
|
+
canvas.height = window.innerHeight;
|
|
58
|
+
} else {
|
|
59
|
+
canvas.width = this.options.canvasSize.w;
|
|
60
|
+
canvas.height = this.options.canvasSize.h;
|
|
61
|
+
}
|
|
62
|
+
document.body.append(canvas);
|
|
63
|
+
|
|
64
|
+
// The camera types
|
|
65
|
+
const initialCameraPosition = vec3.create(0, 0, 0);
|
|
66
|
+
// console.log('passed : o.mainCameraParams.responseCoef ', o.mainCameraParams.responseCoef)
|
|
67
|
+
this.mainCameraParams = {
|
|
68
|
+
type: this.options.mainCameraParams.type,
|
|
69
|
+
responseCoef: this.options.mainCameraParams.responseCoef
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
this.cameras = {
|
|
73
|
+
arcball: new ArcballCamera({position: initialCameraPosition}),
|
|
74
|
+
WASD: new WASDCamera({position: initialCameraPosition}),
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
//
|
|
78
|
+
this.label = new MultiLang()
|
|
79
|
+
if(urlQuery.lang != null) {
|
|
80
|
+
this.label.loadMultilang(urlQuery.lang).then((r) => {
|
|
81
|
+
this.label.get = r;
|
|
82
|
+
});
|
|
83
|
+
} else {
|
|
84
|
+
this.label.loadMultilang().then((r) => {
|
|
85
|
+
this.label.get = r;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
this.init({canvas, callback})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
init = async ({canvas, callback}) => {
|
|
93
|
+
this.canvas = canvas;
|
|
94
|
+
this.adapter = await navigator.gpu.requestAdapter();
|
|
95
|
+
this.device = await this.adapter.requestDevice({
|
|
96
|
+
extensions: ["ray_tracing"]
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// Maybe works in ssl with webworkers...
|
|
100
|
+
// const adapterInfo = await this.adapter.requestAdapterInfo();
|
|
101
|
+
// var test = this.adapter.features()
|
|
102
|
+
// console.log(adapterInfo.vendor);
|
|
103
|
+
// console.log('test' + test);
|
|
104
|
+
// console.log("FEATURES : " + this.adapter.features)
|
|
105
|
+
|
|
106
|
+
this.context = canvas.getContext('webgpu');
|
|
107
|
+
|
|
108
|
+
const devicePixelRatio = window.devicePixelRatio;
|
|
109
|
+
canvas.width = canvas.clientWidth * devicePixelRatio;
|
|
110
|
+
canvas.height = canvas.clientHeight * devicePixelRatio;
|
|
111
|
+
const presentationFormat = navigator.gpu.getPreferredCanvasFormat();
|
|
112
|
+
|
|
113
|
+
this.context.configure({
|
|
114
|
+
device: this.device,
|
|
115
|
+
format: presentationFormat,
|
|
116
|
+
alphaMode: 'premultiplied',
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
if(this.options.useSingleRenderPass == true) {
|
|
120
|
+
this.frame = this.frameSinglePass;
|
|
121
|
+
} else {
|
|
122
|
+
this.frame = this.framePassPerObject;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
this.run(callback)
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
// Not in use for now
|
|
129
|
+
addCube = (o) => {
|
|
130
|
+
if(typeof o === 'undefined') {
|
|
131
|
+
var o = {
|
|
132
|
+
scale: 1,
|
|
133
|
+
position: {x: 0, y: 0, z: -4},
|
|
134
|
+
texturesPaths: ['./res/textures/default.png'],
|
|
135
|
+
rotation: {x: 0, y: 0, z: 0},
|
|
136
|
+
rotationSpeed: {x: 0, y: 0, z: 0},
|
|
137
|
+
entityArgPass: this.entityArgPass,
|
|
138
|
+
cameras: this.cameras,
|
|
139
|
+
mainCameraParams: this.mainCameraParams
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
if(typeof o.position === 'undefined') {o.position = {x: 0, y: 0, z: -4}}
|
|
143
|
+
if(typeof o.rotation === 'undefined') {o.rotation = {x: 0, y: 0, z: 0}}
|
|
144
|
+
if(typeof o.rotationSpeed === 'undefined') {o.rotationSpeed = {x: 0, y: 0, z: 0}}
|
|
145
|
+
if(typeof o.texturesPaths === 'undefined') {o.texturesPaths = ['./res/textures/default.png']}
|
|
146
|
+
if(typeof o.scale === 'undefined') {o.scale = 1;}
|
|
147
|
+
if(typeof o.mainCameraParams === 'undefined') {o.mainCameraParams = this.mainCameraParams}
|
|
148
|
+
o.entityArgPass = this.entityArgPass;
|
|
149
|
+
o.cameras = this.cameras;
|
|
150
|
+
}
|
|
151
|
+
let myCube1 = new MECube(this.canvas, this.device, this.context, o)
|
|
152
|
+
this.mainRenderBundle.push(myCube1);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Not in use for now
|
|
156
|
+
addBall = (o) => {
|
|
157
|
+
if(typeof o === 'undefined') {
|
|
158
|
+
var o = {
|
|
159
|
+
scale: 1,
|
|
160
|
+
position: {x: 0, y: 0, z: -4},
|
|
161
|
+
texturesPaths: ['./res/textures/default.png'],
|
|
162
|
+
rotation: {x: 0, y: 0, z: 0},
|
|
163
|
+
rotationSpeed: {x: 0, y: 0, z: 0},
|
|
164
|
+
entityArgPass: this.entityArgPass,
|
|
165
|
+
cameras: this.cameras,
|
|
166
|
+
mainCameraParams: this.mainCameraParams
|
|
167
|
+
}
|
|
168
|
+
} else {
|
|
169
|
+
if(typeof o.position === 'undefined') {o.position = {x: 0, y: 0, z: -4}}
|
|
170
|
+
if(typeof o.rotation === 'undefined') {o.rotation = {x: 0, y: 0, z: 0}}
|
|
171
|
+
if(typeof o.rotationSpeed === 'undefined') {o.rotationSpeed = {x: 0, y: 0, z: 0}}
|
|
172
|
+
if(typeof o.texturesPaths === 'undefined') {o.texturesPaths = ['./res/textures/default.png']}
|
|
173
|
+
if(typeof o.mainCameraParams === 'undefined') {o.mainCameraParams = this.mainCameraParams}
|
|
174
|
+
if(typeof o.scale === 'undefined') {o.scale = 1;}
|
|
175
|
+
o.entityArgPass = this.entityArgPass;
|
|
176
|
+
o.cameras = this.cameras;
|
|
177
|
+
}
|
|
178
|
+
let myBall1 = new MEBall(this.canvas, this.device, this.context, o)
|
|
179
|
+
this.mainRenderBundle.push(myBall1);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Not in use for now
|
|
183
|
+
addMesh = (o) => {
|
|
184
|
+
if(typeof o.position === 'undefined') {o.position = {x: 0, y: 0, z: -4}}
|
|
185
|
+
if(typeof o.rotation === 'undefined') {o.rotation = {x: 0, y: 0, z: 0}}
|
|
186
|
+
if(typeof o.rotationSpeed === 'undefined') {o.rotationSpeed = {x: 0, y: 0, z: 0}}
|
|
187
|
+
if(typeof o.texturesPaths === 'undefined') {o.texturesPaths = ['./res/textures/default.png']}
|
|
188
|
+
if(typeof o.mainCameraParams === 'undefined') {o.mainCameraParams = this.mainCameraParams}
|
|
189
|
+
if(typeof o.scale === 'undefined') {o.scale = 1;}
|
|
190
|
+
o.entityArgPass = this.entityArgPass;
|
|
191
|
+
o.cameras = this.cameras;
|
|
192
|
+
if(typeof o.name === 'undefined') {o.name = 'random' + Math.random();}
|
|
193
|
+
if(typeof o.mesh === 'undefined') {
|
|
194
|
+
throw console.error('arg mesh is empty...');
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
console.log('Mesh procedure', o)
|
|
198
|
+
let myMesh1 = new MEMesh(this.canvas, this.device, this.context, o)
|
|
199
|
+
this.mainRenderBundle.push(myMesh1);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
addMeshObj = (o) => {
|
|
203
|
+
if(typeof o.name === 'undefined') {o.name = genName(9)}
|
|
204
|
+
if(typeof o.position === 'undefined') {o.position = {x: 0, y: 0, z: -4}}
|
|
205
|
+
if(typeof o.rotation === 'undefined') {o.rotation = {x: 0, y: 0, z: 0}}
|
|
206
|
+
if(typeof o.rotationSpeed === 'undefined') {o.rotationSpeed = {x: 0, y: 0, z: 0}}
|
|
207
|
+
if(typeof o.texturesPaths === 'undefined') {o.texturesPaths = ['./res/textures/default.png']}
|
|
208
|
+
if(typeof o.mainCameraParams === 'undefined') {o.mainCameraParams = this.mainCameraParams}
|
|
209
|
+
if(typeof o.scale === 'undefined') {o.scale = [1, 1, 1];}
|
|
210
|
+
if(typeof o.raycast === 'undefined') {o.raycast = { enabled: false }}
|
|
211
|
+
|
|
212
|
+
o.entityArgPass = this.entityArgPass;
|
|
213
|
+
o.cameras = this.cameras;
|
|
214
|
+
// if(typeof o.name === 'undefined') {o.name = 'random' + Math.random();}
|
|
215
|
+
if(typeof o.mesh === 'undefined') {
|
|
216
|
+
mb.error('arg mesh is empty for ', o.name);
|
|
217
|
+
throw console.error('arg mesh is empty...');
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if(typeof o.physics === 'undefined') {
|
|
221
|
+
o.physics = {
|
|
222
|
+
scale: [1, 1, 1],
|
|
223
|
+
enabled: true,
|
|
224
|
+
geometry: "Sphere",
|
|
225
|
+
radius: o.scale,
|
|
226
|
+
name: o.name,
|
|
227
|
+
rotation: o.rotation
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if(typeof o.physics.enabled === 'undefined') {o.physics.enabled = true}
|
|
231
|
+
if(typeof o.physics.geometry === 'undefined') {o.physics.geometry = "Sphere"}
|
|
232
|
+
if(typeof o.physics.radius === 'undefined') {o.physics.radius = o.scale}
|
|
233
|
+
if(typeof o.physics.mass === 'undefined') {o.physics.mass = 1;}
|
|
234
|
+
if(typeof o.physics.name === 'undefined') {o.physics.name = o.name;}
|
|
235
|
+
if(typeof o.physics.scale === 'undefined') {o.physics.scale = o.scale;}
|
|
236
|
+
if(typeof o.physics.rotation === 'undefined') {o.physics.rotation = o.rotation;}
|
|
237
|
+
|
|
238
|
+
// send same pos
|
|
239
|
+
o.physics.position = o.position;
|
|
240
|
+
// console.log('Mesh procedure', o)
|
|
241
|
+
let myMesh1 = new MEMeshObj(this.canvas, this.device, this.context, o)
|
|
242
|
+
if(o.physics.enabled == true) {
|
|
243
|
+
this.matrixAmmo.addPhysics(myMesh1, o.physics)
|
|
244
|
+
}
|
|
245
|
+
this.mainRenderBundle.push(myMesh1);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
run(callback) {
|
|
249
|
+
setTimeout(() => {requestAnimationFrame(this.frame)}, 500)
|
|
250
|
+
setTimeout(() => {callback(this)}, 20)
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
destroyProgram = () => {
|
|
254
|
+
this.mainRenderBundle = undefined;
|
|
255
|
+
this.canvas.remove();
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
frameSinglePass = () => {
|
|
259
|
+
if(typeof this.mainRenderBundle == 'undefined') return;
|
|
260
|
+
try {
|
|
261
|
+
let shadowPass = null;
|
|
262
|
+
let renderPass;
|
|
263
|
+
let commandEncoder = this.device.createCommandEncoder();
|
|
264
|
+
|
|
265
|
+
this.mainRenderBundle.forEach((meItem, index) => {
|
|
266
|
+
meItem.position.update();
|
|
267
|
+
})
|
|
268
|
+
|
|
269
|
+
this.matrixAmmo.updatePhysics()
|
|
270
|
+
|
|
271
|
+
this.mainRenderBundle.forEach((meItem, index) => {
|
|
272
|
+
meItem.draw(commandEncoder);
|
|
273
|
+
|
|
274
|
+
shadowPass = commandEncoder.beginRenderPass(meItem.shadowPassDescriptor);
|
|
275
|
+
shadowPass.setPipeline(meItem.shadowPipeline);
|
|
276
|
+
meItem.drawShadows(shadowPass);
|
|
277
|
+
shadowPass.end();
|
|
278
|
+
})
|
|
279
|
+
|
|
280
|
+
this.mainRenderBundle.forEach((meItem, index) => {
|
|
281
|
+
if(index == 0) {
|
|
282
|
+
renderPass = commandEncoder.beginRenderPass(meItem.renderPassDescriptor);
|
|
283
|
+
renderPass.setPipeline(meItem.pipeline);
|
|
284
|
+
}
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
this.mainRenderBundle.forEach((meItem, index) => {
|
|
288
|
+
meItem.drawElements(renderPass);
|
|
289
|
+
})
|
|
290
|
+
if(renderPass) renderPass.end();
|
|
291
|
+
|
|
292
|
+
this.device.queue.submit([commandEncoder.finish()]);
|
|
293
|
+
requestAnimationFrame(this.frame);
|
|
294
|
+
} catch(err) {
|
|
295
|
+
console.log('%cDraw func (err):' + err, LOG_WARN)
|
|
296
|
+
requestAnimationFrame(this.frame);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
framePassPerObject = () => {
|
|
301
|
+
// console.log('framePassPerObject')
|
|
302
|
+
let commandEncoder = this.device.createCommandEncoder();
|
|
303
|
+
this.rbContainer = [];
|
|
304
|
+
let passEncoder;
|
|
305
|
+
this.mainRenderBundle.forEach((meItem, index) => {
|
|
306
|
+
meItem.draw(commandEncoder);
|
|
307
|
+
|
|
308
|
+
if(meItem.renderBundle) {
|
|
309
|
+
this.rbContainer.push(meItem.renderBundle)
|
|
310
|
+
passEncoder = commandEncoder.beginRenderPass(meItem.renderPassDescriptor);
|
|
311
|
+
passEncoder.executeBundles(this.rbContainer);
|
|
312
|
+
passEncoder.end();
|
|
313
|
+
} else {
|
|
314
|
+
meItem.draw(commandEncoder)
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
})
|
|
318
|
+
this.device.queue.submit([commandEncoder.finish()]);
|
|
319
|
+
requestAnimationFrame(this.frame);
|
|
320
|
+
}
|
|
321
|
+
|
|
259
322
|
}
|