@woosh/meep-engine 2.43.44 → 2.43.46
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/editor/process/symbolic/makeSolidArrowGeometry.js +391 -0
- package/engine/asset/loaders/image/codec/CodecWithFallback.js +6 -2
- package/engine/graphics/ecs/decal/v2/prototypeDecalSystem.js +115 -7
- package/engine/graphics/ecs/mesh-v2/render/adapters/InstancedRendererAdapter.js +2 -5
- package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_ACCUMULATION.js +12 -6
- package/package.json +1 -1
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import { StreamGeometryBuilder } from "../../../engine/graphics/ecs/path/tube/build/StreamGeometryBuilder.js";
|
|
2
|
+
import { make_ring_faces } from "../../../engine/graphics/ecs/path/tube/build/make_ring_faces.js";
|
|
3
|
+
import { BufferGeometry } from "three/src/core/BufferGeometry.js";
|
|
4
|
+
import { Float32BufferAttribute } from "three/src/core/BufferAttribute.js";
|
|
5
|
+
import { Vector2, Vector3 } from "three";
|
|
6
|
+
|
|
7
|
+
// Modified from https://github.com/mrdoob/three.js/blob/master/src/geometries/CylinderBufferGeometry.js
|
|
8
|
+
class ArrowBufferGeometry extends BufferGeometry {
|
|
9
|
+
|
|
10
|
+
constructor( {radiusTop = 1/7, radiusBottom = 1/20, height = 1, heightTop = 0.6, radialSegments = 8, heightSegments = 1, openEnded = false, heightIncludesHead = true} = {} ) {
|
|
11
|
+
|
|
12
|
+
super();
|
|
13
|
+
this.type = 'ArrowBufferGeometry';
|
|
14
|
+
|
|
15
|
+
this.parameters = {
|
|
16
|
+
radiusTop: radiusTop,
|
|
17
|
+
radiusBottom: radiusBottom,
|
|
18
|
+
height: height,
|
|
19
|
+
heightTop: heightTop,
|
|
20
|
+
radialSegments: radialSegments,
|
|
21
|
+
heightSegments: heightSegments,
|
|
22
|
+
openEnded: openEnded,
|
|
23
|
+
heightIncludesHead: heightIncludesHead,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const scope = this;
|
|
27
|
+
const thetaStart = 0, thetaLength = 2 * Math.PI;
|
|
28
|
+
|
|
29
|
+
radialSegments = Math.floor( radialSegments );
|
|
30
|
+
heightSegments = Math.floor( heightSegments );
|
|
31
|
+
|
|
32
|
+
// buffers
|
|
33
|
+
|
|
34
|
+
const indices = [];
|
|
35
|
+
const vertices = [];
|
|
36
|
+
const normals = [];
|
|
37
|
+
const uvs = [];
|
|
38
|
+
|
|
39
|
+
// helper variables
|
|
40
|
+
|
|
41
|
+
let index = 0;
|
|
42
|
+
const indexArray = [];
|
|
43
|
+
const halfHeight = height / 2;
|
|
44
|
+
const tubeHeight = heightIncludesHead ? height - heightTop : height;
|
|
45
|
+
let groupStart = 0;
|
|
46
|
+
|
|
47
|
+
// generate geometry
|
|
48
|
+
|
|
49
|
+
generateTorso();
|
|
50
|
+
generateCap( true );
|
|
51
|
+
generateCap( false, true );
|
|
52
|
+
|
|
53
|
+
if ( openEnded === false ) {
|
|
54
|
+
|
|
55
|
+
if ( radiusBottom > 0 ) generateCap( false );
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// build geometry
|
|
60
|
+
|
|
61
|
+
this.setIndex( indices );
|
|
62
|
+
this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
|
63
|
+
this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
|
|
64
|
+
this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
|
65
|
+
|
|
66
|
+
function generateTorso() {
|
|
67
|
+
|
|
68
|
+
const normal = new Vector3();
|
|
69
|
+
const vertex = new Vector3();
|
|
70
|
+
|
|
71
|
+
let groupCount = 0;
|
|
72
|
+
|
|
73
|
+
// this will be used to calculate the normal
|
|
74
|
+
const slope = 0;
|
|
75
|
+
|
|
76
|
+
// generate vertices, normals and uvs
|
|
77
|
+
|
|
78
|
+
for ( let y = 0; y <= heightSegments; y ++ ) {
|
|
79
|
+
|
|
80
|
+
const indexRow = [];
|
|
81
|
+
|
|
82
|
+
const v = y / heightSegments;
|
|
83
|
+
|
|
84
|
+
// calculate the radius of the current row
|
|
85
|
+
|
|
86
|
+
const radius = radiusBottom;
|
|
87
|
+
|
|
88
|
+
for ( let x = 0; x <= radialSegments; x ++ ) {
|
|
89
|
+
|
|
90
|
+
const u = x / radialSegments;
|
|
91
|
+
|
|
92
|
+
const theta = u * Math.PI * 2;
|
|
93
|
+
|
|
94
|
+
const sinTheta = Math.sin( theta );
|
|
95
|
+
const cosTheta = Math.cos( theta );
|
|
96
|
+
|
|
97
|
+
// vertex
|
|
98
|
+
|
|
99
|
+
vertex.x = radius * cosTheta;
|
|
100
|
+
vertex.y = radius * sinTheta;
|
|
101
|
+
vertex.z = v * tubeHeight;
|
|
102
|
+
vertices.push( vertex.x, vertex.y, vertex.z );
|
|
103
|
+
|
|
104
|
+
// normal
|
|
105
|
+
|
|
106
|
+
normal.set( cosTheta, sinTheta, 0 ).normalize();
|
|
107
|
+
normals.push( normal.x, normal.y, normal.z );
|
|
108
|
+
|
|
109
|
+
// uv
|
|
110
|
+
|
|
111
|
+
uvs.push( u, 1 - v );
|
|
112
|
+
|
|
113
|
+
// save index of vertex in respective row
|
|
114
|
+
|
|
115
|
+
indexRow.push( index ++ );
|
|
116
|
+
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// now save vertices of the row in our index array
|
|
120
|
+
|
|
121
|
+
indexArray.push( indexRow );
|
|
122
|
+
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// generate indices
|
|
126
|
+
|
|
127
|
+
for ( let x = 0; x < radialSegments; x ++ ) {
|
|
128
|
+
|
|
129
|
+
for ( let y = 0; y < heightSegments; y ++ ) {
|
|
130
|
+
|
|
131
|
+
// we use the index array to access the correct indices
|
|
132
|
+
|
|
133
|
+
const a = indexArray[ y ][ x ];
|
|
134
|
+
const b = indexArray[ y + 1 ][ x ];
|
|
135
|
+
const c = indexArray[ y + 1 ][ x + 1 ];
|
|
136
|
+
const d = indexArray[ y ][ x + 1 ];
|
|
137
|
+
|
|
138
|
+
// faces
|
|
139
|
+
|
|
140
|
+
indices.push( b, a, d );
|
|
141
|
+
indices.push( c, b, d );
|
|
142
|
+
|
|
143
|
+
// update group counter
|
|
144
|
+
|
|
145
|
+
groupCount += 6;
|
|
146
|
+
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// add a group to the geometry. this will ensure multi material support
|
|
152
|
+
|
|
153
|
+
scope.addGroup( groupStart, groupCount, 0 );
|
|
154
|
+
|
|
155
|
+
// calculate new start value for groups
|
|
156
|
+
|
|
157
|
+
groupStart += groupCount;
|
|
158
|
+
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function generateCap( top, headBase = false ) {
|
|
162
|
+
|
|
163
|
+
// save the index of the first center vertex
|
|
164
|
+
const centerIndexStart = index;
|
|
165
|
+
|
|
166
|
+
const uv = new Vector2();
|
|
167
|
+
const vertex = new Vector3();
|
|
168
|
+
|
|
169
|
+
let groupCount = 0;
|
|
170
|
+
|
|
171
|
+
const radius = ( top || headBase ) ? radiusTop : radiusBottom;
|
|
172
|
+
const sign = ( top ) ? 1 : -1;
|
|
173
|
+
|
|
174
|
+
// first we generate the center vertex data of the cap.
|
|
175
|
+
// because the geometry needs one set of uvs per face,
|
|
176
|
+
// we must generate a center vertex per face/segment
|
|
177
|
+
|
|
178
|
+
for ( let x = 1; x <= radialSegments; x ++ ) {
|
|
179
|
+
|
|
180
|
+
// vertex
|
|
181
|
+
|
|
182
|
+
vertices.push( 0, 0, top ? tubeHeight + heightTop : (headBase ? tubeHeight : 0) );
|
|
183
|
+
|
|
184
|
+
// normal
|
|
185
|
+
|
|
186
|
+
if (top) {
|
|
187
|
+
const theta = (x - 1/2) / radialSegments * Math.PI * 2;
|
|
188
|
+
const sinTheta = Math.sin(theta), cosTheta = Math.cos(theta);
|
|
189
|
+
const normal = new Vector3( cosTheta, sinTheta, radiusTop / heightTop );
|
|
190
|
+
normal.normalize();
|
|
191
|
+
normals.push( normal.x, normal.y, normal.z);
|
|
192
|
+
} else {
|
|
193
|
+
normals.push( 0, 0, sign );
|
|
194
|
+
}
|
|
195
|
+
// uv
|
|
196
|
+
|
|
197
|
+
uvs.push( 0.5, 0.5 );
|
|
198
|
+
|
|
199
|
+
// increase index
|
|
200
|
+
|
|
201
|
+
index ++;
|
|
202
|
+
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// save the index of the last center vertex
|
|
206
|
+
const centerIndexEnd = index;
|
|
207
|
+
|
|
208
|
+
// now we generate the surrounding vertices, normals and uvs
|
|
209
|
+
|
|
210
|
+
for ( let x = 0; x <= radialSegments; x ++ ) {
|
|
211
|
+
|
|
212
|
+
const u = x / radialSegments;
|
|
213
|
+
const theta = u * thetaLength + thetaStart;
|
|
214
|
+
|
|
215
|
+
const cosTheta = Math.cos( theta );
|
|
216
|
+
const sinTheta = Math.sin( theta );
|
|
217
|
+
|
|
218
|
+
// vertex
|
|
219
|
+
|
|
220
|
+
vertex.x = radius * cosTheta;
|
|
221
|
+
vertex.y = radius * sinTheta;
|
|
222
|
+
vertex.z = top || headBase ? tubeHeight : 0;
|
|
223
|
+
vertices.push( vertex.x, vertex.y, vertex.z );
|
|
224
|
+
|
|
225
|
+
// normal
|
|
226
|
+
|
|
227
|
+
if (top) {
|
|
228
|
+
const normal = new Vector3(cosTheta, sinTheta, radiusTop / heightTop );
|
|
229
|
+
normal.normalize();
|
|
230
|
+
normals.push( normal.x, normal.y, normal.z);
|
|
231
|
+
} else {
|
|
232
|
+
normals.push( 0, 0, sign );
|
|
233
|
+
}
|
|
234
|
+
// uv
|
|
235
|
+
|
|
236
|
+
uv.x = ( cosTheta * 0.5 ) + 0.5;
|
|
237
|
+
uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
|
|
238
|
+
uvs.push( uv.x, uv.y );
|
|
239
|
+
|
|
240
|
+
// increase index
|
|
241
|
+
|
|
242
|
+
index ++;
|
|
243
|
+
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// generate indices
|
|
247
|
+
|
|
248
|
+
for ( let x = 0; x < radialSegments; x ++ ) {
|
|
249
|
+
|
|
250
|
+
const c = centerIndexStart + x;
|
|
251
|
+
const i = centerIndexEnd + x;
|
|
252
|
+
|
|
253
|
+
if ( top === true ) {
|
|
254
|
+
|
|
255
|
+
// face top
|
|
256
|
+
|
|
257
|
+
indices.push( i, i + 1, c );
|
|
258
|
+
|
|
259
|
+
} else {
|
|
260
|
+
|
|
261
|
+
// face bottom
|
|
262
|
+
|
|
263
|
+
indices.push( i + 1, i, c );
|
|
264
|
+
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
groupCount += 3;
|
|
268
|
+
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// add a group to the geometry. this will ensure multi material support
|
|
272
|
+
|
|
273
|
+
scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
|
|
274
|
+
|
|
275
|
+
// calculate new start value for groups
|
|
276
|
+
|
|
277
|
+
groupStart += groupCount;
|
|
278
|
+
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
*
|
|
287
|
+
* @param {StreamGeometryBuilder} out
|
|
288
|
+
* @param {number} count
|
|
289
|
+
* @param {number} radius
|
|
290
|
+
* @param {number} z
|
|
291
|
+
*/
|
|
292
|
+
function make_ring_vertices(out, count, radius, z) {
|
|
293
|
+
|
|
294
|
+
const positions = out.positions;
|
|
295
|
+
|
|
296
|
+
for (let i = 0; i < count; i++) {
|
|
297
|
+
|
|
298
|
+
const vertex_index = out.cursor_vertices++;
|
|
299
|
+
|
|
300
|
+
const fraction = i / count;
|
|
301
|
+
|
|
302
|
+
const angle = Math.PI * 2 * fraction;
|
|
303
|
+
|
|
304
|
+
const vertex_offset = vertex_index * 3;
|
|
305
|
+
|
|
306
|
+
positions[vertex_offset] = Math.cos(angle) * radius;
|
|
307
|
+
positions[vertex_offset + 1] = Math.sin(angle) * radius;
|
|
308
|
+
positions[vertex_offset + 2] = z;
|
|
309
|
+
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
*
|
|
316
|
+
* @param {StreamGeometryBuilder} out
|
|
317
|
+
* @param {number} count
|
|
318
|
+
* @param {number} vertex_offset
|
|
319
|
+
* @param {number} tip_vertex_index
|
|
320
|
+
*/
|
|
321
|
+
function make_cone_indices(out, count, vertex_offset, tip_vertex_index) {
|
|
322
|
+
const indices = out.indices;
|
|
323
|
+
|
|
324
|
+
for (let i = 0; i < count; i++) {
|
|
325
|
+
const index_0 = i + vertex_offset;
|
|
326
|
+
const index_1 = tip_vertex_index;
|
|
327
|
+
const index_2 = ((i + 1) % count) + vertex_offset;
|
|
328
|
+
|
|
329
|
+
const triangle_index = out.cursor_indices++;
|
|
330
|
+
|
|
331
|
+
const triangle_offset = triangle_index * 3;
|
|
332
|
+
|
|
333
|
+
indices[triangle_offset] = index_1;
|
|
334
|
+
indices[triangle_offset + 1] = index_2;
|
|
335
|
+
indices[triangle_offset + 2] = index_0;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export function makeSolidArrowGeometry(){
|
|
341
|
+
return new ArrowBufferGeometry();
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function makeSolidArrowGeometry2(
|
|
345
|
+
radial_resolution = 16,
|
|
346
|
+
pointer_length = 0.5,
|
|
347
|
+
pointer_width = 0.2,
|
|
348
|
+
stem_width = 0.1
|
|
349
|
+
) {
|
|
350
|
+
|
|
351
|
+
const Z_OFFSET = -0.5;
|
|
352
|
+
|
|
353
|
+
const vertex_count = radial_resolution * 3 + 1;
|
|
354
|
+
|
|
355
|
+
const triangle_count = radial_resolution //arrow cap
|
|
356
|
+
+ radial_resolution * 2 // under-arrow ring
|
|
357
|
+
+ radial_resolution * 2 // stem
|
|
358
|
+
+ radial_resolution //cap for base of the stem
|
|
359
|
+
;
|
|
360
|
+
|
|
361
|
+
const builder = new StreamGeometryBuilder();
|
|
362
|
+
|
|
363
|
+
builder.allocate(vertex_count, triangle_count);
|
|
364
|
+
|
|
365
|
+
const positions = builder.positions;
|
|
366
|
+
|
|
367
|
+
// write tip
|
|
368
|
+
const tip_vertex_index = builder.cursor_vertices++;
|
|
369
|
+
positions[tip_vertex_index * 3] = 0;
|
|
370
|
+
positions[tip_vertex_index * 3 + 1] = 0;
|
|
371
|
+
positions[tip_vertex_index * 3 + 2] = Z_OFFSET + 1;
|
|
372
|
+
|
|
373
|
+
const ring_0_start = builder.cursor_vertices;
|
|
374
|
+
|
|
375
|
+
// make cone ring - arrow cap
|
|
376
|
+
make_ring_vertices(builder, radial_resolution, pointer_width, Z_OFFSET + 1 - pointer_length);
|
|
377
|
+
make_cone_indices(builder, radial_resolution, ring_0_start, tip_vertex_index);
|
|
378
|
+
|
|
379
|
+
const ring_1_start = builder.cursor_vertices;
|
|
380
|
+
|
|
381
|
+
// make ring 1
|
|
382
|
+
make_ring_vertices(builder, radial_resolution, stem_width, Z_OFFSET + 1 - pointer_length);
|
|
383
|
+
make_ring_faces(builder, ring_1_start, 1, radial_resolution);
|
|
384
|
+
|
|
385
|
+
const ring_2_start = builder.cursor_vertices;
|
|
386
|
+
|
|
387
|
+
make_ring_vertices(builder, radial_resolution, stem_width, Z_OFFSET + 0);
|
|
388
|
+
make_ring_faces(builder, ring_2_start, 1, radial_resolution);
|
|
389
|
+
|
|
390
|
+
return builder.build();
|
|
391
|
+
}
|
|
@@ -22,7 +22,9 @@ export class CodecWithFallback extends Codec {
|
|
|
22
22
|
for (let i = 0; i < codec_count; i++) {
|
|
23
23
|
const codec = codecs[i];
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
const codec_supports_data = await codec.test(data);
|
|
26
|
+
|
|
27
|
+
if (codec_supports_data) {
|
|
26
28
|
return true;
|
|
27
29
|
}
|
|
28
30
|
}
|
|
@@ -42,7 +44,9 @@ export class CodecWithFallback extends Codec {
|
|
|
42
44
|
for (let i = 0; i < codec_count; i++) {
|
|
43
45
|
const codec = codecs[i];
|
|
44
46
|
|
|
45
|
-
|
|
47
|
+
const codec_supports_data = await codec.test(data);
|
|
48
|
+
|
|
49
|
+
if (!codec_supports_data) {
|
|
46
50
|
errors.push({
|
|
47
51
|
index: i, error: "Codec doesn't support this data"
|
|
48
52
|
});
|
|
@@ -16,6 +16,16 @@ import { GLTFAssetLoader } from "../../../../asset/loaders/GLTFAssetLoader.js";
|
|
|
16
16
|
import '../../../../../../../../css/game.scss';
|
|
17
17
|
import { countTask } from "../../../../../core/process/task/util/countTask.js";
|
|
18
18
|
import Vector2 from "../../../../../core/geom/Vector2.js";
|
|
19
|
+
import { RotationBehavior } from "../../../../intelligence/behavior/util/RotationBehavior.js";
|
|
20
|
+
import { BehaviorComponent } from "../../../../intelligence/behavior/ecs/BehaviorComponent.js";
|
|
21
|
+
import Vector3 from "../../../../../core/geom/Vector3.js";
|
|
22
|
+
import { ShadedGeometry } from "../../mesh-v2/ShadedGeometry.js";
|
|
23
|
+
import { makeHelperBoxGeometry } from "../../../../../editor/process/symbolic/makeHelperBoxGeometry.js";
|
|
24
|
+
import { DoubleSide, LineBasicMaterial, MeshStandardMaterial } from "three";
|
|
25
|
+
import { DrawMode } from "../../mesh-v2/DrawMode.js";
|
|
26
|
+
import { OctahedralUvEncoder } from "../../../impostors/octahedral/grid/OctahedralUvEncoder.js";
|
|
27
|
+
import { makeSolidArrowGeometry } from "../../../../../editor/process/symbolic/makeSolidArrowGeometry.js";
|
|
28
|
+
import { vec3 } from "gl-matrix";
|
|
19
29
|
|
|
20
30
|
const decal_urls = `data/textures/icons/FantasyIconsMegaPack/MagicItems/MagicItems_png/transparent/x64/staff_13_t.png
|
|
21
31
|
data/textures/icons/FantasyIconsMegaPack/MagicItems/MagicItems_png/transparent/x64/artifact_01_t.png
|
|
@@ -217,7 +227,7 @@ function promise_time_out(t) {
|
|
|
217
227
|
* @param {number} spacing
|
|
218
228
|
* @param {string[]} textures
|
|
219
229
|
*/
|
|
220
|
-
function grid(ecd, offset_x, offset_y,x, y, size_x, size_y, spacing, textures) {
|
|
230
|
+
function grid(ecd, offset_x, offset_y, x, y, size_x, size_y, spacing, textures) {
|
|
221
231
|
|
|
222
232
|
const random = seededRandom();
|
|
223
233
|
|
|
@@ -243,7 +253,7 @@ function grid(ecd, offset_x, offset_y,x, y, size_x, size_y, spacing, textures) {
|
|
|
243
253
|
// transform.rotation.set(0,0.7,0,0.7);
|
|
244
254
|
transform.rotation.set(-0.7, 0, 0, 0.7);
|
|
245
255
|
// transform.rotation.random(random);
|
|
246
|
-
transform.scale.set(size_x, size_y,1
|
|
256
|
+
transform.scale.set(size_x, size_y, 1);
|
|
247
257
|
// transform.scale.setScalar(1);
|
|
248
258
|
|
|
249
259
|
entity
|
|
@@ -256,6 +266,100 @@ function grid(ecd, offset_x, offset_y,x, y, size_x, size_y, spacing, textures) {
|
|
|
256
266
|
|
|
257
267
|
}
|
|
258
268
|
|
|
269
|
+
function makeNormalTestGridDecal(ecd) {
|
|
270
|
+
|
|
271
|
+
const GRID_OFFSET = new Vector3(5, 0, 5);
|
|
272
|
+
|
|
273
|
+
const uv = new OctahedralUvEncoder();
|
|
274
|
+
|
|
275
|
+
const GRID_SIZE = 9;
|
|
276
|
+
|
|
277
|
+
const SPACING = 2;
|
|
278
|
+
|
|
279
|
+
const DEBUG_BOX = makeHelperBoxGeometry();
|
|
280
|
+
|
|
281
|
+
for (let i = 0; i < GRID_SIZE; i++) {
|
|
282
|
+
for (let j = 0; j < GRID_SIZE; j++) {
|
|
283
|
+
|
|
284
|
+
const direction = [];
|
|
285
|
+
|
|
286
|
+
uv.uv_to_unit(direction, [i / (GRID_SIZE - 1), j / (GRID_SIZE - 1)]);
|
|
287
|
+
|
|
288
|
+
vec3.negate(direction,direction);
|
|
289
|
+
|
|
290
|
+
const decal = new Decal();
|
|
291
|
+
|
|
292
|
+
decal.uri = decal_urls[1];
|
|
293
|
+
|
|
294
|
+
const entity = new EntityBuilder();
|
|
295
|
+
|
|
296
|
+
entity.clearFlag(EntityBuilderFlags.WatchDestruction);
|
|
297
|
+
|
|
298
|
+
const transform = new Transform();
|
|
299
|
+
transform.position.set(
|
|
300
|
+
SPACING * i,
|
|
301
|
+
0,
|
|
302
|
+
SPACING * j
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
transform.position.add(GRID_OFFSET);
|
|
306
|
+
|
|
307
|
+
transform.scale.setScalar(1);
|
|
308
|
+
transform.rotation._lookRotation(direction[0], direction[1], direction[2], 0, 1, 0);
|
|
309
|
+
|
|
310
|
+
entity
|
|
311
|
+
.add(ShadedGeometry.from(DEBUG_BOX, new LineBasicMaterial(), DrawMode.LineSegments))
|
|
312
|
+
.add(transform)
|
|
313
|
+
.add(decal)
|
|
314
|
+
.build(ecd);
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
// make an arrow helper
|
|
318
|
+
const arrow_transform = Transform.fromJSON({
|
|
319
|
+
position: new Vector3(0, 0, -0.5)
|
|
320
|
+
});
|
|
321
|
+
arrow_transform.multiplyTransforms(transform, arrow_transform);
|
|
322
|
+
|
|
323
|
+
new EntityBuilder()
|
|
324
|
+
.add(ShadedGeometry.from(makeSolidArrowGeometry(), new MeshStandardMaterial({
|
|
325
|
+
side: DoubleSide
|
|
326
|
+
}), DrawMode.Triangles))
|
|
327
|
+
.add(arrow_transform)
|
|
328
|
+
.build(ecd);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* @returns {EntityBuilder}
|
|
335
|
+
*/
|
|
336
|
+
function makeNormalTestDecal() {
|
|
337
|
+
const decal = new Decal();
|
|
338
|
+
|
|
339
|
+
decal.uri = decal_urls[1];
|
|
340
|
+
|
|
341
|
+
const entity = new EntityBuilder();
|
|
342
|
+
|
|
343
|
+
entity.clearFlag(EntityBuilderFlags.WatchDestruction);
|
|
344
|
+
|
|
345
|
+
const transform = new Transform();
|
|
346
|
+
transform.position.set(
|
|
347
|
+
5,
|
|
348
|
+
0,
|
|
349
|
+
5
|
|
350
|
+
);
|
|
351
|
+
transform.scale.setScalar(1);
|
|
352
|
+
transform.rotation.lookRotation(Vector3.down);
|
|
353
|
+
|
|
354
|
+
entity
|
|
355
|
+
.add(ShadedGeometry.from(DEBUG_BOX, new LineBasicMaterial(), DrawMode.LineSegments))
|
|
356
|
+
.add(transform)
|
|
357
|
+
.add(decal)
|
|
358
|
+
.add(BehaviorComponent.fromOne(RotationBehavior.fromJSON({ speed: 1, axis: Vector3.left })))
|
|
359
|
+
|
|
360
|
+
return entity;
|
|
361
|
+
}
|
|
362
|
+
|
|
259
363
|
/**
|
|
260
364
|
*
|
|
261
365
|
* @param {Engine} engine
|
|
@@ -281,7 +385,9 @@ async function main(engine) {
|
|
|
281
385
|
|
|
282
386
|
const random = seededRandom();
|
|
283
387
|
|
|
284
|
-
const ENTITY_COUNT =
|
|
388
|
+
const ENTITY_COUNT = 1;
|
|
389
|
+
|
|
390
|
+
const ecd = engine.entityManager.dataset;
|
|
285
391
|
|
|
286
392
|
function makeOne() {
|
|
287
393
|
const decal = new Decal();
|
|
@@ -304,9 +410,9 @@ async function main(engine) {
|
|
|
304
410
|
entity
|
|
305
411
|
.add(transform)
|
|
306
412
|
.add(decal)
|
|
307
|
-
|
|
413
|
+
.add(BehaviorComponent.fromOne(RotationBehavior.fromJSON({ speed: 1 })))
|
|
308
414
|
|
|
309
|
-
entity.build(
|
|
415
|
+
entity.build(ecd);
|
|
310
416
|
}
|
|
311
417
|
|
|
312
418
|
// for (let i = 0; i < ENTITY_COUNT; i++) {
|
|
@@ -316,6 +422,8 @@ async function main(engine) {
|
|
|
316
422
|
|
|
317
423
|
const task = countTask(0, ENTITY_COUNT, makeOne);
|
|
318
424
|
|
|
425
|
+
makeNormalTestGridDecal(ecd);
|
|
426
|
+
|
|
319
427
|
// TaskLoadingScreen.instance.load(engine, task);
|
|
320
428
|
|
|
321
429
|
// console.profile('spawn');
|
|
@@ -327,9 +435,9 @@ async function main(engine) {
|
|
|
327
435
|
// engine.executor.run(task);
|
|
328
436
|
|
|
329
437
|
|
|
330
|
-
grid(engine.entityManager.dataset, 20,10,80, 25, .4, .6, .1, decal_urls.slice(105, 105+3));
|
|
438
|
+
//grid(engine.entityManager.dataset, 20,10,80, 25, .4, .6, .1, decal_urls.slice(105, 105+3));
|
|
331
439
|
|
|
332
|
-
grid(engine.entityManager.dataset, 20,30,80, 25, .4, .6, .1, decal_urls.slice(105, 105+3));
|
|
440
|
+
//grid(engine.entityManager.dataset, 20,30,80, 25, .4, .6, .1, decal_urls.slice(105, 105+3));
|
|
333
441
|
// await promise_time_out(10);
|
|
334
442
|
|
|
335
443
|
|
|
@@ -2,7 +2,6 @@ import { AbstractRenderAdapter } from "./AbstractRenderAdapter.js";
|
|
|
2
2
|
import { HashMap } from "../../../../../../core/collection/HashMap.js";
|
|
3
3
|
import { InstancedMeshGroup } from "../../../../geometry/instancing/InstancedMeshGroup.js";
|
|
4
4
|
import { ShadedGeometryFlags } from "../../ShadedGeometryFlags.js";
|
|
5
|
-
import { DrawMode } from "../../DrawMode.js";
|
|
6
5
|
import { StreamDrawUsage } from "three";
|
|
7
6
|
|
|
8
7
|
const INSTANCED_EQUALITY_FLAGS = ShadedGeometryFlags.CastShadow
|
|
@@ -68,14 +67,12 @@ export class InstancedRendererAdapter extends AbstractRenderAdapter {
|
|
|
68
67
|
|
|
69
68
|
} else {
|
|
70
69
|
|
|
71
|
-
if (sg.mode !== DrawMode.Triangles) {
|
|
72
|
-
throw new Error(`Unsupported draw mode ${sg.mode}`);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
70
|
im = new InstancedMeshGroup();
|
|
76
71
|
im.instance_usage = StreamDrawUsage;
|
|
77
72
|
im.shrinkFactor = 0; // prevent shrinking as we're essentially rebuilding this geometry frame
|
|
78
73
|
|
|
74
|
+
im.draw_mode = sg.mode;
|
|
75
|
+
|
|
79
76
|
im.setMaterial(sg.material);
|
|
80
77
|
im.setGeometry(sg.geometry);
|
|
81
78
|
|
|
@@ -60,16 +60,22 @@ export const FP_SHADER_CHUNK_ACCUMULATION = `
|
|
|
60
60
|
// we're inside decal volume
|
|
61
61
|
vec4 light_data_4 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+4u), 0);
|
|
62
62
|
|
|
63
|
-
// compute normal of the decal
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
// compute normal of the decal, we get this by extracting rotation matrix and transforming (0,1,0) vector using that
|
|
64
|
+
|
|
65
|
+
mat4 decal_view_transform = viewMatrix*decal_transform_matrix;
|
|
66
|
+
|
|
67
|
+
vec3 decal_normal = normalize(vec3(
|
|
68
|
+
decal_view_transform[1][0], decal_view_transform[1][1], decal_view_transform[1][2]
|
|
69
|
+
));
|
|
70
|
+
|
|
71
|
+
float decal_surface_dot = dot(decal_normal, geometry.normal);
|
|
66
72
|
|
|
67
73
|
// we fade out decals when the projection angle to the surface gets too steep
|
|
68
74
|
// 0.7 is cos(45deg) and 0.5 is cos(60deg), dot returns cos of angle between two normals
|
|
69
|
-
float decal_surface_angle_fade = smoothstep(
|
|
75
|
+
float decal_surface_angle_fade = smoothstep(0.7,0.5,decal_surface_dot);
|
|
70
76
|
|
|
71
77
|
if(decal_surface_angle_fade <= 0.0){
|
|
72
|
-
|
|
78
|
+
continue;
|
|
73
79
|
}
|
|
74
80
|
|
|
75
81
|
vec2 decal_local_uv = (local_position.xy + 0.5);
|
|
@@ -81,7 +87,7 @@ export const FP_SHADER_CHUNK_ACCUMULATION = `
|
|
|
81
87
|
float decal_alpha = decal_color.a * decal_surface_angle_fade;
|
|
82
88
|
|
|
83
89
|
if(decal_alpha < 0.003){
|
|
84
|
-
|
|
90
|
+
continue;
|
|
85
91
|
}
|
|
86
92
|
|
|
87
93
|
material.diffuseColor = material.diffuseColor*(1.0-decal_alpha) + decal_color.xyz*decal_alpha;
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"productName": "Meep",
|
|
6
6
|
"description": "production-ready JavaScript game engine based on Entity Component System Architecture",
|
|
7
7
|
"author": "Alexander Goldring",
|
|
8
|
-
"version": "2.43.
|
|
8
|
+
"version": "2.43.46",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"gl-matrix": "3.4.3",
|
|
11
11
|
"fast-levenshtein": "2.0.6",
|