@woosh/meep-engine 2.34.31 → 2.34.32
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/core/collection/table/DataTypeByteSizes.js +16 -0
- package/engine/ecs/transform/Transform.js +1 -1
- package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +16 -3
- package/engine/graphics/ecs/mesh-v2/sample/load_gltf.js +52 -0
- package/engine/graphics/ecs/mesh-v2/{prototypeShadedGeometry.js → sample/prototypeShadedGeometry.js} +5 -5
- package/engine/graphics/ecs/mesh-v2/three_object_to_entity_composition.js +37 -0
- package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +15 -0
- package/engine/graphics/micron/build/compute_micron_buffer_array_constructor.js +2 -0
- package/engine/graphics/micron/build/fill_patch_geometry_data.js +35 -2
- package/engine/graphics/micron/prototypeVirtualGeometry.js +7 -1
- package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +3 -0
- package/engine/graphics/micron/render/instanced/shader/shader_rewrite_standard.js +23 -0
- package/package.json +1 -1
|
@@ -19,3 +19,19 @@ export const DataTypeByteSizes = {
|
|
|
19
19
|
[DataType.Float32]: 4,
|
|
20
20
|
[DataType.Float64]: 8
|
|
21
21
|
};
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @param {DataType} type
|
|
27
|
+
* @return {number}
|
|
28
|
+
*/
|
|
29
|
+
export function dataTypeByteSize(type) {
|
|
30
|
+
const size = DataTypeByteSizes[type];
|
|
31
|
+
|
|
32
|
+
if (size === undefined) {
|
|
33
|
+
throw new Error(`Unsupported type '${type}'`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return size;
|
|
37
|
+
}
|
|
@@ -125,16 +125,29 @@ export class ShadedGeometry {
|
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
__build_object() {
|
|
128
|
+
/**
|
|
129
|
+
* @type {THREE.Object3D}
|
|
130
|
+
*/
|
|
131
|
+
let object;
|
|
132
|
+
|
|
128
133
|
const mode = this.mode;
|
|
134
|
+
const shader = this.material;
|
|
135
|
+
const geo = this.geometry;
|
|
136
|
+
|
|
129
137
|
if (mode === DrawMode.Triangles) {
|
|
130
|
-
|
|
138
|
+
object = new Mesh(geo, shader);
|
|
131
139
|
} else if (mode === DrawMode.Lines) {
|
|
132
|
-
|
|
140
|
+
object = new Line(geo, shader);
|
|
133
141
|
} else if (mode === DrawMode.LineSegments) {
|
|
134
|
-
|
|
142
|
+
object = new LineSegments(geo, shader);
|
|
135
143
|
} else {
|
|
136
144
|
throw new Error(`Unsupported draw mode '${mode}'`);
|
|
137
145
|
}
|
|
146
|
+
|
|
147
|
+
object.matrixAutoUpdate = false;
|
|
148
|
+
object.frustumCulled = false;
|
|
149
|
+
|
|
150
|
+
this.__cached_object = object;
|
|
138
151
|
}
|
|
139
152
|
|
|
140
153
|
get bvh() {
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { EngineHarness } from "../../../../EngineHarness.js";
|
|
2
|
+
import { ShadedGeometrySystem } from "../ShadedGeometrySystem.js";
|
|
3
|
+
import { GameAssetType } from "../../../../asset/GameAssetType.js";
|
|
4
|
+
import { EngineConfiguration } from "../../../../EngineConfiguration.js";
|
|
5
|
+
import { GLTFAssetLoader } from "../../../../asset/loaders/GLTFAssetLoader.js";
|
|
6
|
+
import { three_object_to_entity_composition } from "../three_object_to_entity_composition.js";
|
|
7
|
+
|
|
8
|
+
const eh = new EngineHarness();
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @param {EngineHarness} harness
|
|
13
|
+
* @return {Promise<void>}
|
|
14
|
+
*/
|
|
15
|
+
async function init(harness) {
|
|
16
|
+
const engine = harness.engine;
|
|
17
|
+
|
|
18
|
+
const config = new EngineConfiguration();
|
|
19
|
+
|
|
20
|
+
config.addSystem(new ShadedGeometrySystem(engine));
|
|
21
|
+
config.addLoader(GameAssetType.ModelGLTF_JSON, new GLTFAssetLoader());
|
|
22
|
+
|
|
23
|
+
await config.apply(engine);
|
|
24
|
+
|
|
25
|
+
eh.initialize().then(main);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* @param {Engine} engine
|
|
31
|
+
*/
|
|
32
|
+
async function main(engine) {
|
|
33
|
+
|
|
34
|
+
const em = engine.entityManager;
|
|
35
|
+
|
|
36
|
+
EngineHarness.buildBasics({
|
|
37
|
+
engine,
|
|
38
|
+
enableWater: false
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const ecd = em.dataset;
|
|
42
|
+
|
|
43
|
+
const asset = await engine.assetManager.promise('moicon/06_04_hapro/08-clickable-assets-new/model.gltf', GameAssetType.ModelGLTF_JSON);
|
|
44
|
+
|
|
45
|
+
const three_object = asset.create();
|
|
46
|
+
|
|
47
|
+
const composition = three_object_to_entity_composition(three_object);
|
|
48
|
+
|
|
49
|
+
composition.build(ecd);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
init(eh);
|
package/engine/graphics/ecs/mesh-v2/{prototypeShadedGeometry.js → sample/prototypeShadedGeometry.js}
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { EngineHarness } from "
|
|
2
|
-
import { ShadedGeometrySystem } from "
|
|
3
|
-
import EntityBuilder from "
|
|
4
|
-
import { Transform } from "
|
|
5
|
-
import { ShadedGeometry } from "
|
|
1
|
+
import { EngineHarness } from "../../../../EngineHarness.js";
|
|
2
|
+
import { ShadedGeometrySystem } from "../ShadedGeometrySystem.d.ts";
|
|
3
|
+
import EntityBuilder from "../../../../ecs/EntityBuilder.d.ts";
|
|
4
|
+
import { Transform } from "../../../../ecs/transform/Transform.d.ts";
|
|
5
|
+
import { ShadedGeometry } from "../ShadedGeometry.d.ts";
|
|
6
6
|
import { BoxBufferGeometry, MeshBasicMaterial } from "three";
|
|
7
7
|
|
|
8
8
|
const eh = new EngineHarness();
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { EntityNode } from "../../../ecs/parent/EntityNode.js";
|
|
2
|
+
import { Transform } from "../../../ecs/transform/Transform.js";
|
|
3
|
+
import { ShadedGeometry } from "./ShadedGeometry.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {THREE.Object3D} root
|
|
8
|
+
* @returns {EntityNode}
|
|
9
|
+
*/
|
|
10
|
+
export function three_object_to_entity_composition(root) {
|
|
11
|
+
const node = new EntityNode();
|
|
12
|
+
|
|
13
|
+
const transform = new Transform();
|
|
14
|
+
transform.fromMatrix4(root.matrix.elements);
|
|
15
|
+
|
|
16
|
+
node.entity.add(transform);
|
|
17
|
+
|
|
18
|
+
if (root.isMesh) {
|
|
19
|
+
if (root.isSkinnedMesh) {
|
|
20
|
+
throw new Error(`Skinned meshes are not supported`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
node.entity.add(ShadedGeometry.from(root.geometry, root.material));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const children = root.children;
|
|
27
|
+
const child_count = children.length;
|
|
28
|
+
for (let i = 0; i < child_count; i++) {
|
|
29
|
+
const child = children[i];
|
|
30
|
+
|
|
31
|
+
const child_node = three_object_to_entity_composition(child);
|
|
32
|
+
|
|
33
|
+
node.addChild(child_node);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return node;
|
|
37
|
+
}
|
|
@@ -51,6 +51,17 @@ function custom_attribute_format_uv(spec, source) {
|
|
|
51
51
|
spec.type = DataType.Float16;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
/**
|
|
55
|
+
*
|
|
56
|
+
* @param {AttributeSpec} spec
|
|
57
|
+
* @param {THREE.BufferAttribute} source
|
|
58
|
+
*/
|
|
59
|
+
function custom_attribute_format_color(spec, source) {
|
|
60
|
+
// crush color data to 8 bit
|
|
61
|
+
spec.type = DataType.Uint8;
|
|
62
|
+
spec.normalized = true;
|
|
63
|
+
}
|
|
64
|
+
|
|
54
65
|
/**
|
|
55
66
|
*
|
|
56
67
|
* @param {AttributeSpec} spec
|
|
@@ -70,7 +81,11 @@ function format_attribute(spec, source, name) {
|
|
|
70
81
|
case 'normal':
|
|
71
82
|
custom_attribute_format_normal(spec, source);
|
|
72
83
|
break;
|
|
84
|
+
case 'color':
|
|
85
|
+
custom_attribute_format_color(spec, source);
|
|
86
|
+
break;
|
|
73
87
|
default:
|
|
88
|
+
spec.normalized = source.normalized;
|
|
74
89
|
spec.type = typedArrayToDataType(source.array)
|
|
75
90
|
}
|
|
76
91
|
|
|
@@ -9,6 +9,9 @@ import { DataType } from "../../../../core/collection/table/DataType.js";
|
|
|
9
9
|
import { passThrough } from "../../../../core/function/Functions.js";
|
|
10
10
|
import { to_half_float_uint16 } from "../../../../core/binary/to_half_float_uint16.js";
|
|
11
11
|
import { compute_micron_buffer_array_constructor } from "./compute_micron_buffer_array_constructor.js";
|
|
12
|
+
import { typedArrayToDataType } from "../../../../core/collection/array/typedArrayToDataType.js";
|
|
13
|
+
import { dataTypeByteSize } from "../../../../core/collection/table/DataTypeByteSizes.js";
|
|
14
|
+
import { clamp } from "../../../../core/math/clamp.js";
|
|
12
15
|
|
|
13
16
|
function UintArrayForCount(count) {
|
|
14
17
|
|
|
@@ -90,6 +93,17 @@ function copy_attribute_data(vertex_count, index_map_backward, itemSize, attribu
|
|
|
90
93
|
}
|
|
91
94
|
}
|
|
92
95
|
|
|
96
|
+
/**
|
|
97
|
+
*
|
|
98
|
+
* @param {number} value
|
|
99
|
+
* @returns {number}
|
|
100
|
+
*/
|
|
101
|
+
function resample_normalized_uint16_to_uint8(value) {
|
|
102
|
+
const normalized = clamp(value / 65535, 0, 1);
|
|
103
|
+
|
|
104
|
+
return Math.round(normalized * 255);
|
|
105
|
+
}
|
|
106
|
+
|
|
93
107
|
/**
|
|
94
108
|
*
|
|
95
109
|
* @param {number} value
|
|
@@ -105,7 +119,8 @@ function normalize_to_int8(value) {
|
|
|
105
119
|
const DataConverterType = {
|
|
106
120
|
None: passThrough,
|
|
107
121
|
Number2HalfFloat: to_half_float_uint16,
|
|
108
|
-
Normalize2Int8: normalize_to_int8
|
|
122
|
+
Normalize2Int8: normalize_to_int8,
|
|
123
|
+
ResampleNormalized_Uint16_to_Uint8: resample_normalized_uint16_to_uint8
|
|
109
124
|
};
|
|
110
125
|
|
|
111
126
|
/**
|
|
@@ -125,7 +140,25 @@ function compute_attribute_data_converter(source, spec) {
|
|
|
125
140
|
throw new Error(`Unsupported normalized type '${spec.type}'`);
|
|
126
141
|
}
|
|
127
142
|
} else {
|
|
128
|
-
|
|
143
|
+
const source_array = source.array;
|
|
144
|
+
|
|
145
|
+
const source_type = typedArrayToDataType(source_array);
|
|
146
|
+
|
|
147
|
+
const target_byte_size = dataTypeByteSize(spec.type);
|
|
148
|
+
const source_byte_size = dataTypeByteSize(source_type)
|
|
149
|
+
|
|
150
|
+
if (target_byte_size !== source_byte_size) {
|
|
151
|
+
// wrong data size
|
|
152
|
+
|
|
153
|
+
if (spec.type === DataType.Uint8 && source_type === DataType.Uint16) {
|
|
154
|
+
return DataConverterType.ResampleNormalized_Uint16_to_Uint8;
|
|
155
|
+
} else {
|
|
156
|
+
throw new Error(`Unsupported conversion ${source_type} -> `);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
} else {
|
|
160
|
+
return DataConverterType.None;
|
|
161
|
+
}
|
|
129
162
|
}
|
|
130
163
|
}
|
|
131
164
|
|
|
@@ -455,7 +455,7 @@ function init() {
|
|
|
455
455
|
}
|
|
456
456
|
|
|
457
457
|
// sample_gltf_sponza();
|
|
458
|
-
gltf_sample('data/models/RTS_Buildings_Humans/18/Building_R_18_out/Building_R_18.gltf');
|
|
458
|
+
// gltf_sample('data/models/RTS_Buildings_Humans/18/Building_R_18_out/Building_R_18.gltf');
|
|
459
459
|
// sample_lucy();
|
|
460
460
|
// sample_gltf_hapro_2();
|
|
461
461
|
// sample_gltf_hapro_1();
|
|
@@ -468,6 +468,12 @@ function init() {
|
|
|
468
468
|
// gltf_sample('moicon/29_Dec_2021_Nammo/1/model.gltf');
|
|
469
469
|
// gltf_sample('moicon/29_Dec_2021_Nammo/1-onematerial/model.gltf');
|
|
470
470
|
// gltf_sample('moicon/29_Dec_2021_Nammo/2/model.gltf');
|
|
471
|
+
// gltf_sample('moicon/03_Jan_22_Demo/1-ground_floor/model.gltf');
|
|
472
|
+
// gltf_sample('moicon/03_Jan_22_Demo/2-1st_floor/model.gltf');
|
|
473
|
+
// gltf_sample('moicon/03_Jan_22_Demo/3-area_ground_floor/model.gltf');
|
|
474
|
+
// gltf_sample('moicon/03_Jan_22_Demo/4-area_1st_floor/model.gltf');
|
|
475
|
+
// gltf_sample('moicon/03_Jan_22_Demo/8-assets/model.gltf');
|
|
476
|
+
gltf_sample('moicon/03_Jan_22_Demo/worker_test/model.gltf');
|
|
471
477
|
|
|
472
478
|
document.addEventListener("mousemove", onDocumentMouseMove);
|
|
473
479
|
|
|
@@ -160,6 +160,29 @@ export function shader_rewrite_standard(shader, uniforms, spec, column_count) {
|
|
|
160
160
|
|
|
161
161
|
if (attribute_spec_color !== undefined) {
|
|
162
162
|
// using color
|
|
163
|
+
const vx_color_value = `texelFetch(${gen_micron_vertex_attribute_texture_name('color')}, micron_vertex_uv, 0)`
|
|
164
|
+
|
|
165
|
+
rewrittenVertexShader = rewrittenVertexShader.replace(
|
|
166
|
+
'#include <color_vertex>',
|
|
167
|
+
`
|
|
168
|
+
#if defined( USE_COLOR_ALPHA )
|
|
169
|
+
vColor = vec4( 1.0 );
|
|
170
|
+
#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )
|
|
171
|
+
vColor = vec3( 1.0 );
|
|
172
|
+
#endif
|
|
173
|
+
|
|
174
|
+
#ifdef USE_COLOR
|
|
175
|
+
|
|
176
|
+
#ifdef USE_COLOR_ALPHA
|
|
177
|
+
vColor *= ${vx_color_value}.rgba;
|
|
178
|
+
#else
|
|
179
|
+
vColor *= ${vx_color_value}.rgb;
|
|
180
|
+
#endif
|
|
181
|
+
|
|
182
|
+
#endif
|
|
183
|
+
|
|
184
|
+
`
|
|
185
|
+
);
|
|
163
186
|
|
|
164
187
|
}
|
|
165
188
|
|
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.34.
|
|
8
|
+
"version": "2.34.32",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"gl-matrix": "3.4.3",
|
|
11
11
|
"fast-levenshtein": "2.0.6",
|