@woosh/meep-engine 2.42.1 → 2.42.3

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.
@@ -42,6 +42,21 @@ export class RingBuffer {
42
42
  this.data = new Array(size);
43
43
  }
44
44
 
45
+ /**
46
+ *
47
+ * @param {number} new_size
48
+ */
49
+ resize(new_size) {
50
+ const array = new Array(new_size);
51
+
52
+ this.data = array;
53
+ this.size = new_size;
54
+
55
+ this.clear();
56
+
57
+ // TODO implement a way to keep the old data, need to figure out the correct adjustments to head and tail
58
+ }
59
+
45
60
  /**
46
61
  *
47
62
  * @return {V}
@@ -2,6 +2,7 @@ export class AbstractMetric {
2
2
  /**
3
3
  *
4
4
  * @param {number} value
5
+ * @returns {void}
5
6
  */
6
7
  record(value) {
7
8
  throw new Error('Not implemented');
@@ -23,7 +24,7 @@ export class AbstractMetric {
23
24
  throw new Error('Not implemented');
24
25
  }
25
26
 
26
- clear(){
27
+ clear() {
27
28
  throw new Error('Not implemented');
28
29
  }
29
30
  }
@@ -9,9 +9,23 @@ export class RingBufferMetric extends AbstractMetric {
9
9
  constructor(size = 100) {
10
10
  super();
11
11
 
12
+ /**
13
+ *
14
+ * @type {RingBuffer}
15
+ * @readonly
16
+ * @private
17
+ */
12
18
  this.__data = new RingBuffer(size);
13
19
  }
14
20
 
21
+ /**
22
+ * Resize underlying buffer to be able to keep a different number of records
23
+ * @param {number} size
24
+ */
25
+ resize(size) {
26
+ this.__data.resize(size);
27
+ }
28
+
15
29
  getLastRecord() {
16
30
  return this.__data.getHead();
17
31
  }
@@ -0,0 +1,138 @@
1
+ import { EngineHarness } from "../../../../EngineHarness.js";
2
+ import EntityBuilder from "../../../../ecs/EntityBuilder.js";
3
+ import { SGMesh } from "../../mesh-v2/aggregate/SGMesh.js";
4
+ import { Transform } from "../../../../ecs/transform/Transform.js";
5
+ import { GLTFAssetLoader } from "../../../../asset/loaders/GLTFAssetLoader.js";
6
+ import { GameAssetType } from "../../../../asset/GameAssetType.js";
7
+ import { FPDecalSystem } from "./FPDecalSystem.js";
8
+ import { BehaviorSystem } from "../../../../intelligence/behavior/ecs/BehaviorSystem.js";
9
+ import { SGMeshSystem } from "../../mesh-v2/aggregate/SGMeshSystem.js";
10
+ import { ShadedGeometrySystem } from "../../mesh-v2/ShadedGeometrySystem.js";
11
+ import { TransformAttachmentSystem } from "../../../../ecs/transform-attachment/TransformAttachmentSystem.js";
12
+ import ListView from "../../../../../view/common/ListView.js";
13
+ import List from "../../../../../core/collection/list/List.js";
14
+ import ImageView from "../../../../../view/elements/image/ImageView.js";
15
+ import GUIElement from "../../../../ecs/gui/GUIElement.js";
16
+ import GUIElementSystem from "../../../../ecs/gui/GUIElementSystem.js";
17
+ import ObservedInteger from "../../../../../core/model/ObservedInteger.js";
18
+ import ObservedString from "../../../../../core/model/ObservedString.js";
19
+ import { MouseEvents } from "../../../../input/devices/events/MouseEvents.js";
20
+
21
+ class EditorState {
22
+ selected_entity = new ObservedInteger(-1)
23
+
24
+ }
25
+
26
+ /**
27
+ *
28
+ * @param {Engine} engine
29
+ * @param {ObservedString} selected
30
+ * @returns {ImageView|ListView}
31
+ */
32
+ function makeDecalSelector({ engine, selected }) {
33
+ const decal_uris = new List(
34
+ `data/textures/icons/FantasyIconsMegaPack/MagicItems/MagicItems_png/transparent/x64/artifact_03_t.png
35
+ data/textures/icons/FantasyIconsMegaPack/MagicItems/MagicItems_png/transparent/x64/artifact_04_t.png
36
+ data/textures/icons/FantasyIconsMegaPack/MagicItems/MagicItems_png/transparent/x64/artifact_05_t.png
37
+ data/textures/icons/FantasyIconsMegaPack/MagicItems/MagicItems_png/transparent/x64/artifact_06_t.png
38
+ data/textures/icons/FantasyIconsMegaPack/MagicItems/MagicItems_png/transparent/x64/artifact_07_t.png
39
+ data/textures/icons/FantasyIconsMegaPack/MagicItems/MagicItems_png/transparent/x64/artifact_08_t.png
40
+ data/textures/icons/FantasyIconsMegaPack/MagicItems/MagicItems_png/transparent/x64/artifact_09_t.png
41
+ data/textures/icons/FantasyIconsMegaPack/MagicItems/MagicItems_png/transparent/x64/artifact_10_t.png
42
+ data/textures/icons/FantasyIconsMegaPack/MagicItems/MagicItems_png/transparent/x64/artifact_11_t.png`
43
+ .trim()
44
+ .split('\n')
45
+ .map(s => s.trim())
46
+ .filter(s => s.length > 0)
47
+ );
48
+
49
+ const listView = new ListView(decal_uris, {
50
+ elementFactory(el) {
51
+ const element_view = new ImageView(el);
52
+
53
+ element_view.css({
54
+ pointerEvents: 'auto',
55
+ boxSizing: 'border-box',
56
+ });
57
+
58
+ element_view.size.setScalar(64);
59
+
60
+ const process_selection = (e) => {
61
+ const is_selected = e === el;
62
+
63
+ element_view.css({
64
+ border: is_selected ? `2px solid red` : 'none'
65
+ });
66
+ };
67
+
68
+ element_view.bindSignal(selected.onChanged, process_selection);
69
+ process_selection(selected.getValue());
70
+
71
+ element_view.el.addEventListener(MouseEvents.Click, () => {
72
+ selected.set(el);
73
+ });
74
+
75
+ return element_view;
76
+ }
77
+ });
78
+
79
+ listView.css({
80
+ backgroundImage:
81
+ `url(../data/textures/utility/checkers_white_grey_256x256.png)`,
82
+ backgroundSize: "24px 24px", /* Must be a square */
83
+ backgroundPosition: "0 0, 12px 0, 12px -12px, 0px 12px"
84
+ });
85
+
86
+ listView.size.set(600, 128);
87
+
88
+ return listView;
89
+ }
90
+
91
+ /**
92
+ *
93
+ * @param {Engine} engine
94
+ */
95
+ async function main(engine) {
96
+
97
+ await EngineHarness.buildBasics({
98
+ engine,
99
+ enableWater: false,
100
+ cameraFarDistance: 300
101
+ });
102
+
103
+ const ecd = engine.entityManager.dataset;
104
+
105
+ new EntityBuilder()
106
+ .add(SGMesh.fromURL("moicon/gnutti_not_optimized/model.gltf"))
107
+ .add(Transform.fromJSON({
108
+ position: { x: 10, y: 3, z: 10 },
109
+ scale: 1.5
110
+ }));
111
+
112
+ // decal selector
113
+
114
+ const selected_decal_uri = new ObservedString('');
115
+
116
+ new EntityBuilder()
117
+ .add(GUIElement.fromView(makeDecalSelector({ engine, selected: selected_decal_uri })))
118
+ .build(ecd);
119
+
120
+ }
121
+
122
+ new EngineHarness()
123
+ .initialize({
124
+ configuration(config, engine) {
125
+ const gltfAssetLoader = new GLTFAssetLoader();
126
+
127
+ config.addLoader(GameAssetType.ModelGLTF_JSON, gltfAssetLoader);
128
+ config.addLoader(GameAssetType.ModelGLTF, gltfAssetLoader);
129
+
130
+ config.addSystem(new FPDecalSystem(engine));
131
+ config.addSystem(new BehaviorSystem(engine))
132
+ config.addSystem(new SGMeshSystem(engine));
133
+ config.addSystem(new ShadedGeometrySystem(engine));
134
+ config.addSystem(new TransformAttachmentSystem(engine));
135
+
136
+ config.addSystem(new GUIElementSystem(engine.gui.view, engine));
137
+ }
138
+ }).then(main);
@@ -1,89 +1,93 @@
1
1
  export const FP_SHADER_CHUNK_ACCUMULATION = `
2
- ivec3 v3_cluster_resolution = textureSize(fp_t_light_tiles, 0);
3
- ivec3 v3_cluster_position = ivec3( clip_v.x * float(v3_cluster_resolution.x), clip_v.y*float(v3_cluster_resolution.y), (clip_v.z)*float(v3_cluster_resolution.z) );
4
-
5
- uvec3 cluster_metadata = texelFetch(fp_t_light_tiles, v3_cluster_position , 0).rgb;
6
-
7
- // read light data
8
- for(uint i=0u; i < cluster_metadata.y; i++){
9
- uint lookup_index = cluster_metadata.x + i;
2
+ #ifndef FP_SHADER_CHUNK_ACCUMULATION
3
+ #define FP_SHADER_CHUNK_ACCUMULATION
4
+
5
+ ivec3 v3_cluster_resolution = textureSize(fp_t_light_tiles, 0);
6
+ ivec3 v3_cluster_position = ivec3( clip_v.x * float(v3_cluster_resolution.x), clip_v.y*float(v3_cluster_resolution.y), (clip_v.z)*float(v3_cluster_resolution.z) );
10
7
 
11
- uint light_descriptor = texelFetch(fp_t_light_lookup, address_to_data_texture_coordinates(lookup_index), 0 ).r;
8
+ uvec3 cluster_metadata = texelFetch(fp_t_light_tiles, v3_cluster_position , 0).rgb;
9
+
10
+ // read light data
11
+ for(uint i=0u; i < cluster_metadata.y; i++){
12
+ uint lookup_index = cluster_metadata.x + i;
12
13
 
13
- uint type = (light_descriptor) & 0x3u;
14
- uint light_address = light_descriptor >> 2;
15
-
14
+ uint light_descriptor = texelFetch(fp_t_light_lookup, address_to_data_texture_coordinates(lookup_index), 0 ).r;
16
15
 
17
- if(type == 0u){
18
- // point light
19
-
20
- vec4 light_data_0 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address), 0);
21
- vec4 light_data_1 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+1u), 0);
22
-
23
- vec3 light_position = light_data_0.xyz;
24
- float light_radius = light_data_0.w;
25
-
26
- vec3 light_color = light_data_1.xyz;
27
- float light_intensity = light_data_1.w;
28
-
29
- PointLight pointlight;
30
-
31
- pointlight.position = light_position;
32
- pointlight.distance = light_radius;
33
- pointlight.color = light_color*light_intensity;
34
- pointlight.decay = 1.0;
35
-
36
- fp_getPointDirectLightIrradiance( pointlight, directLight, vViewPosition );
37
- RE_Direct( directLight, geometry, material, reflectedLight );
38
-
39
- }else if(type == 3u){
40
- // decal
41
- vec4 light_data_0 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address), 0);
42
- vec4 light_data_1 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+1u), 0);
43
- vec4 light_data_2 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+2u), 0);
44
- vec4 light_data_3 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+3u), 0);
45
-
46
- mat4 decal_transform_matrix = mat4(
47
- light_data_0,
48
- light_data_1,
49
- light_data_2,
50
- light_data_3
51
- );
52
-
53
- vec4 local_position = decal_transform_matrix*vec4(v_world_position, 1.0);
54
-
55
- if(max3(abs(local_position.xyz)) < 0.5){
56
-
57
- // we're inside decal volume
58
- vec4 light_data_4 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+4u), 0);
16
+ uint type = (light_descriptor) & 0x3u;
17
+ uint light_address = light_descriptor >> 2;
59
18
 
60
- // compute normal of the decal
61
- vec4 decal_normal = normalize( viewMatrix*decal_transform_matrix*vec4(0.0, 0.0, 1.0, 0.0) );
62
- float decal_surface_dot = dot(decal_normal.xyz, geometry.normal);
19
+
20
+ if(type == 0u){
21
+ // point light
22
+
23
+ vec4 light_data_0 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address), 0);
24
+ vec4 light_data_1 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+1u), 0);
25
+
26
+ vec3 light_position = light_data_0.xyz;
27
+ float light_radius = light_data_0.w;
28
+
29
+ vec3 light_color = light_data_1.xyz;
30
+ float light_intensity = light_data_1.w;
31
+
32
+ PointLight pointlight;
33
+
34
+ pointlight.position = light_position;
35
+ pointlight.distance = light_radius;
36
+ pointlight.color = light_color*light_intensity;
37
+ pointlight.decay = 1.0;
38
+
39
+ fp_getPointDirectLightIrradiance( pointlight, directLight, vViewPosition );
40
+ RE_Direct( directLight, geometry, material, reflectedLight );
63
41
 
64
- // we fade out decals when the projection angle to the surface gets too steep
65
- // 0.7 is cos(45deg) and 0.5 is cos(60deg), dot returns cos of angle between two normals
66
- float decal_surface_angle_fade = smoothstep(-0.5,-0.7,decal_surface_dot);
67
-
68
- if(decal_surface_angle_fade <= 0.0){
69
- continue;
70
- }
71
-
72
- vec2 decal_local_uv = (local_position.xy + 0.5);
73
- vec2 decal_uv = decal_local_uv*light_data_4.zw + light_data_4.xy;
74
-
75
- vec4 decal_color = texture2D(fp_t_decal_atlas,decal_uv, -0.2);
76
-
77
- // compute decal alpha
78
- float decal_alpha = decal_color.a * decal_surface_angle_fade;
79
-
80
- if(decal_alpha < 0.003){
81
- continue;
82
- }
83
-
84
- material.diffuseColor = material.diffuseColor*(1.0-decal_alpha) + decal_color.xyz*decal_alpha;
85
- }
86
-
87
- }
42
+ }else if(type == 3u){
43
+ // decal
44
+ vec4 light_data_0 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address), 0);
45
+ vec4 light_data_1 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+1u), 0);
46
+ vec4 light_data_2 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+2u), 0);
47
+ vec4 light_data_3 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+3u), 0);
48
+
49
+ mat4 decal_transform_matrix = mat4(
50
+ light_data_0,
51
+ light_data_1,
52
+ light_data_2,
53
+ light_data_3
54
+ );
55
+
56
+ vec4 local_position = decal_transform_matrix*vec4(v_world_position, 1.0);
57
+
58
+ if(max3(abs(local_position.xyz)) < 0.5){
59
+
60
+ // we're inside decal volume
61
+ vec4 light_data_4 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+4u), 0);
62
+
63
+ // compute normal of the decal
64
+ vec4 decal_normal = normalize( viewMatrix*decal_transform_matrix*vec4(0.0, 0.0, 1.0, 0.0) );
65
+ float decal_surface_dot = dot(decal_normal.xyz, geometry.normal);
66
+
67
+ // we fade out decals when the projection angle to the surface gets too steep
68
+ // 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(-0.5,-0.7,decal_surface_dot);
70
+
71
+ if(decal_surface_angle_fade <= 0.0){
72
+ continue;
73
+ }
74
+
75
+ vec2 decal_local_uv = (local_position.xy + 0.5);
76
+ vec2 decal_uv = decal_local_uv*light_data_4.zw + light_data_4.xy;
77
+
78
+ vec4 decal_color = texture2D(fp_t_decal_atlas,decal_uv, -0.2);
79
+
80
+ // compute decal alpha
81
+ float decal_alpha = decal_color.a * decal_surface_angle_fade;
82
+
83
+ if(decal_alpha < 0.003){
84
+ continue;
85
+ }
86
+
87
+ material.diffuseColor = material.diffuseColor*(1.0-decal_alpha) + decal_color.xyz*decal_alpha;
88
+ }
89
+
88
90
  }
91
+ }
92
+ #endif
89
93
  `;
@@ -1,51 +1,55 @@
1
1
  export const FP_SHADER_CHUNK_DECODE_PARS = `
2
- // don't rely on three.js light number define to ensure that point light calculations are available
3
- #if NUM_POINT_LIGHTS < 1
4
- struct PointLight {
5
- vec3 position;
6
- vec3 color;
7
- float distance;
8
- float decay;
9
- };
10
- #endif
11
-
12
- // directLight is an out parameter as having it as a return value caused compiler errors on some devices
13
- void fp_getPointDirectLightIrradiance( const in PointLight pointLight, out IncidentLight directLight, vec3 viewPosition ) {
14
-
15
- // TODO consider moving light position transformation to view-space over to CPU
16
- vec3 lVector = (viewMatrix*vec4(pointLight.position,1.0)).xyz + viewPosition;
17
-
18
- directLight.direction = normalize( lVector );
19
-
20
- float lightDistance = length( lVector );
21
-
22
- directLight.color = pointLight.color;
23
- directLight.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );
24
- directLight.visible = ( directLight.color != vec3( 0.0 ) );
25
- }
26
-
27
- float convert_depth_to_linear(in float d){
28
- float d_n = 2.0*d - 1.0;
29
-
30
- float f = fp_f_camera_far;
31
- float n = fp_f_camera_near;
32
-
33
- float fn = f*n;
34
-
35
- float z_diff = f - n;
36
-
37
- float denominator = (f + n - d_n * z_diff );
38
-
39
- float z_view = (2.0*fn) / denominator;
40
-
41
- return (z_view - n) / z_diff;
42
- }
43
-
44
- ivec2 address_to_data_texture_coordinates(uint address){
45
- // Lookup texture has 128 width
46
- uint lookup_index_x = address % 128u;
47
- uint lookup_index_y = address >> 7;
48
-
49
- return ivec2(int(lookup_index_x),int(lookup_index_y));
50
- }
51
- `;
2
+ #ifndef FP_SHADER_CHUNK_DECODE_PARS
3
+ #define FP_SHADER_CHUNK_DECODE_PARS
4
+
5
+ // don't rely on three.js light number define to ensure that point light calculations are available
6
+ #if NUM_POINT_LIGHTS < 1
7
+ struct PointLight {
8
+ vec3 position;
9
+ vec3 color;
10
+ float distance;
11
+ float decay;
12
+ };
13
+ #endif
14
+
15
+ // directLight is an out parameter as having it as a return value caused compiler errors on some devices
16
+ void fp_getPointDirectLightIrradiance( const in PointLight pointLight, out IncidentLight directLight, vec3 viewPosition ) {
17
+
18
+ // TODO consider moving light position transformation to view-space over to CPU
19
+ vec3 lVector = (viewMatrix*vec4(pointLight.position,1.0)).xyz + viewPosition;
20
+
21
+ directLight.direction = normalize( lVector );
22
+
23
+ float lightDistance = length( lVector );
24
+
25
+ directLight.color = pointLight.color;
26
+ directLight.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );
27
+ directLight.visible = ( directLight.color != vec3( 0.0 ) );
28
+ }
29
+
30
+ float convert_depth_to_linear(in float d){
31
+ float d_n = 2.0*d - 1.0;
32
+
33
+ float f = fp_f_camera_far;
34
+ float n = fp_f_camera_near;
35
+
36
+ float fn = f*n;
37
+
38
+ float z_diff = f - n;
39
+
40
+ float denominator = (f + n - d_n * z_diff );
41
+
42
+ float z_view = (2.0*fn) / denominator;
43
+
44
+ return (z_view - n) / z_diff;
45
+ }
46
+
47
+ ivec2 address_to_data_texture_coordinates(uint address){
48
+ // Lookup texture has 128 width
49
+ uint lookup_index_x = address % 128u;
50
+ uint lookup_index_y = address >> 7;
51
+
52
+ return ivec2(int(lookup_index_x),int(lookup_index_y));
53
+ }
54
+ #endif
55
+ `;
@@ -1,28 +1,34 @@
1
- export const FP_SHADER_CHUNK_PREAMBLE = `precision mediump usampler3D;
2
- precision mediump usampler2D;
3
-
4
- uniform usampler3D fp_t_light_tiles;
5
-
6
- uniform usampler2D fp_t_light_lookup;
7
- uniform sampler2D fp_t_light_data;
8
- uniform sampler2D fp_t_decal_atlas;
9
- uniform vec2 fp_t_decal_atlas_resolution;
10
-
11
- uniform vec3 fp_v3_light_cluster_resolution;
12
-
13
- uniform float fp_f_camera_near;
14
- uniform float fp_f_camera_far;
15
-
16
- #define gl_FragDepthEXT gl_FragDepth
17
- #define texture2D texture
18
- #define textureCube texture
19
- #define texture2DProj textureProj
20
- #define texture2DLodEXT textureLod
21
- #define texture2DProjLodEXT textureProjLod
22
- #define textureCubeLodEXT textureLod
23
- #define texture2DGradEXT textureGrad
24
- #define texture2DProjGradEXT textureProjGrad
25
- #define textureCubeGradEXT textureGrad
26
-
27
- uniform vec2 fp_resolution;
1
+ export const FP_SHADER_CHUNK_PREAMBLE = `
2
+ #ifndef FP_SHADER_CHUNK_PREAMBLE
3
+ #define FP_SHADER_CHUNK_PREAMBLE
4
+
5
+ precision mediump usampler3D;
6
+ precision mediump usampler2D;
7
+
8
+ uniform usampler3D fp_t_light_tiles;
9
+
10
+ uniform usampler2D fp_t_light_lookup;
11
+ uniform sampler2D fp_t_light_data;
12
+ uniform sampler2D fp_t_decal_atlas;
13
+ uniform vec2 fp_t_decal_atlas_resolution;
14
+
15
+ uniform vec3 fp_v3_light_cluster_resolution;
16
+
17
+ uniform float fp_f_camera_near;
18
+ uniform float fp_f_camera_far;
19
+
20
+ #define gl_FragDepthEXT gl_FragDepth
21
+ #define texture2D texture
22
+ #define textureCube texture
23
+ #define texture2DProj textureProj
24
+ #define texture2DLodEXT textureLod
25
+ #define texture2DProjLodEXT textureProjLod
26
+ #define textureCubeLodEXT textureLod
27
+ #define texture2DGradEXT textureGrad
28
+ #define texture2DProjGradEXT textureProjGrad
29
+ #define textureCubeGradEXT textureGrad
30
+
31
+ uniform vec2 fp_resolution;
32
+
33
+ #endif
28
34
  `;
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.42.1",
8
+ "version": "2.42.3",
9
9
  "dependencies": {
10
10
  "gl-matrix": "3.4.3",
11
11
  "fast-levenshtein": "2.0.6",