@zephyr3d/scene 0.2.0 → 0.3.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/dist/asset/assetmanager.js +85 -93
- package/dist/asset/assetmanager.js.map +1 -1
- package/dist/camera/camera.js +1 -0
- package/dist/camera/camera.js.map +1 -1
- package/dist/index.d.ts +2511 -2329
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/material/blinn.js +5 -5
- package/dist/material/grassmaterial.js +14 -14
- package/dist/material/material.js +32 -54
- package/dist/material/material.js.map +1 -1
- package/dist/material/meshmaterial.js +215 -80
- package/dist/material/meshmaterial.js.map +1 -1
- package/dist/material/mixins/albedocolor.js +11 -7
- package/dist/material/mixins/albedocolor.js.map +1 -1
- package/dist/material/mixins/foliage.js +7 -7
- package/dist/material/mixins/lightmodel/blinnphong.js +5 -5
- package/dist/material/mixins/lightmodel/lambert.js +5 -5
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +5 -5
- package/dist/material/mixins/lit.js +72 -72
- package/dist/material/mixins/pbr/common.js +4 -4
- package/dist/material/mixins/texture.js +6 -6
- package/dist/material/mixins/vertexcolor.js +5 -5
- package/dist/material/pbrmr.js +5 -5
- package/dist/material/shader/helper.js +20 -18
- package/dist/material/shader/helper.js.map +1 -1
- package/dist/material/terrainmaterial.js +12 -12
- package/dist/posteffect/bloom.js +1 -0
- package/dist/posteffect/bloom.js.map +1 -1
- package/dist/posteffect/compositor.js +1 -0
- package/dist/posteffect/compositor.js.map +1 -1
- package/dist/posteffect/water.js +1 -0
- package/dist/posteffect/water.js.map +1 -1
- package/dist/render/cull_visitor.js +24 -3
- package/dist/render/cull_visitor.js.map +1 -1
- package/dist/render/primitive.js +31 -0
- package/dist/render/primitive.js.map +1 -1
- package/dist/render/render_queue.js +111 -38
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderer.js +9 -0
- package/dist/render/renderer.js.map +1 -1
- package/dist/render/sky.js +2 -4
- package/dist/render/sky.js.map +1 -1
- package/dist/scene/batchgroup.js +126 -0
- package/dist/scene/batchgroup.js.map +1 -0
- package/dist/scene/environment.js +1 -0
- package/dist/scene/environment.js.map +1 -1
- package/dist/scene/graph_node.js +8 -0
- package/dist/scene/graph_node.js.map +1 -1
- package/dist/scene/mesh.js +35 -2
- package/dist/scene/mesh.js.map +1 -1
- package/dist/scene/octree.js +37 -72
- package/dist/scene/octree.js.map +1 -1
- package/dist/scene/octree_update_visitor.js +5 -1
- package/dist/scene/octree_update_visitor.js.map +1 -1
- package/dist/scene/scene.js +7 -17
- package/dist/scene/scene.js.map +1 -1
- package/dist/scene/scene_node.js +57 -44
- package/dist/scene/scene_node.js.map +1 -1
- package/dist/scene/xform.js +61 -36
- package/dist/scene/xform.js.map +1 -1
- package/dist/shadow/esm.js +1 -0
- package/dist/shadow/esm.js.map +1 -1
- package/dist/shadow/shadowmapper.js +22 -6
- package/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/shadow/vsm.js +1 -0
- package/dist/shadow/vsm.js.map +1 -1
- package/dist/shapes/box.js +15 -6
- package/dist/shapes/box.js.map +1 -1
- package/dist/shapes/cylinder.js +1 -4
- package/dist/shapes/cylinder.js.map +1 -1
- package/dist/shapes/shape.js +5 -0
- package/dist/shapes/shape.js.map +1 -1
- package/dist/shapes/sphere.js +3 -0
- package/dist/shapes/sphere.js.map +1 -1
- package/package.json +6 -6
|
@@ -17,13 +17,12 @@ import { Application } from '../app.js';
|
|
|
17
17
|
import '@zephyr3d/device';
|
|
18
18
|
import { CopyBlitter } from '../blitter/copy.js';
|
|
19
19
|
import { getSheenLutLoader, getTestCubemapLoader } from './builtin.js';
|
|
20
|
-
import { GraphNode } from '../scene/graph_node.js';
|
|
21
20
|
import { BUILTIN_ASSET_TEXTURE_SHEEN_LUT, BUILTIN_ASSET_TEST_CUBEMAP } from '../values.js';
|
|
22
21
|
import { TGALoader } from './loaders/image/tga_Loader.js';
|
|
23
22
|
|
|
24
|
-
/**
|
|
25
|
-
* The asset manager
|
|
26
|
-
* @public
|
|
23
|
+
/**
|
|
24
|
+
* The asset manager
|
|
25
|
+
* @public
|
|
27
26
|
*/ class AssetManager {
|
|
28
27
|
/** @internal */ static _builtinTextures = {};
|
|
29
28
|
/** @internal */ static _builtinTextureLoaders = {
|
|
@@ -37,8 +36,8 @@ import { TGALoader } from './loaders/image/tga_Loader.js';
|
|
|
37
36
|
/** @internal */ _models;
|
|
38
37
|
/** @internal */ _binaryDatas;
|
|
39
38
|
/** @internal */ _textDatas;
|
|
40
|
-
/**
|
|
41
|
-
* Creates an instance of AssetManager
|
|
39
|
+
/**
|
|
40
|
+
* Creates an instance of AssetManager
|
|
42
41
|
*/ constructor(){
|
|
43
42
|
this._httpRequest = new HttpRequest();
|
|
44
43
|
this._textureLoaders = [
|
|
@@ -55,21 +54,21 @@ import { TGALoader } from './loaders/image/tga_Loader.js';
|
|
|
55
54
|
this._binaryDatas = {};
|
|
56
55
|
this._textDatas = {};
|
|
57
56
|
}
|
|
58
|
-
/**
|
|
59
|
-
* HttpRequest instance of the asset manager
|
|
57
|
+
/**
|
|
58
|
+
* HttpRequest instance of the asset manager
|
|
60
59
|
*/ get httpRequest() {
|
|
61
60
|
return this._httpRequest;
|
|
62
61
|
}
|
|
63
|
-
/**
|
|
64
|
-
* Removes all cached assets
|
|
62
|
+
/**
|
|
63
|
+
* Removes all cached assets
|
|
65
64
|
*/ clearCache() {
|
|
66
65
|
this._textures = {};
|
|
67
66
|
this._models = {};
|
|
68
67
|
this._binaryDatas = {};
|
|
69
68
|
this._textDatas = {};
|
|
70
69
|
}
|
|
71
|
-
/**
|
|
72
|
-
* Remove and dispose all cached assets
|
|
70
|
+
/**
|
|
71
|
+
* Remove and dispose all cached assets
|
|
73
72
|
*/ purgeCache() {
|
|
74
73
|
for(const k in this._textures){
|
|
75
74
|
this._textures[k].then((tex)=>tex?.dispose()).catch((err)=>{});
|
|
@@ -79,42 +78,42 @@ import { TGALoader } from './loaders/image/tga_Loader.js';
|
|
|
79
78
|
this._binaryDatas = {};
|
|
80
79
|
this._textDatas = {};
|
|
81
80
|
}
|
|
82
|
-
/**
|
|
83
|
-
* Adds a texture loader to the asset manager
|
|
84
|
-
*
|
|
85
|
-
* @remarks
|
|
86
|
-
* TODO: this should be a static method
|
|
87
|
-
*
|
|
88
|
-
* @param loader - The texture loader to be added
|
|
81
|
+
/**
|
|
82
|
+
* Adds a texture loader to the asset manager
|
|
83
|
+
*
|
|
84
|
+
* @remarks
|
|
85
|
+
* TODO: this should be a static method
|
|
86
|
+
*
|
|
87
|
+
* @param loader - The texture loader to be added
|
|
89
88
|
*/ addTextureLoader(loader) {
|
|
90
89
|
if (loader) {
|
|
91
90
|
this._textureLoaders.unshift(loader);
|
|
92
91
|
}
|
|
93
92
|
}
|
|
94
|
-
/**
|
|
95
|
-
* Adds a model loader to the asset manager
|
|
96
|
-
*
|
|
97
|
-
* @remarks
|
|
98
|
-
* TODO: this should be a static method
|
|
99
|
-
*
|
|
100
|
-
* @param loader - The model loader to be added
|
|
93
|
+
/**
|
|
94
|
+
* Adds a model loader to the asset manager
|
|
95
|
+
*
|
|
96
|
+
* @remarks
|
|
97
|
+
* TODO: this should be a static method
|
|
98
|
+
*
|
|
99
|
+
* @param loader - The model loader to be added
|
|
101
100
|
*/ addModelLoader(loader) {
|
|
102
101
|
if (loader) {
|
|
103
102
|
this._modelLoaders.unshift(loader);
|
|
104
103
|
}
|
|
105
104
|
}
|
|
106
|
-
/**
|
|
107
|
-
* Fetches a text resource from a given URL
|
|
108
|
-
* @param url - The URL from where to fetch the resource
|
|
109
|
-
* @param postProcess - A function that will be involved when the text data was loaded.
|
|
110
|
-
*
|
|
111
|
-
* @remarks
|
|
112
|
-
* If a text data has already been loaded, the function will ignore the
|
|
113
|
-
* postProcess parameter and directly return the text loaded previously.
|
|
114
|
-
* To load the same text with different postProcess parameters,
|
|
115
|
-
* use different AssetManager instances separately.
|
|
116
|
-
*
|
|
117
|
-
* @returns The fetched text
|
|
105
|
+
/**
|
|
106
|
+
* Fetches a text resource from a given URL
|
|
107
|
+
* @param url - The URL from where to fetch the resource
|
|
108
|
+
* @param postProcess - A function that will be involved when the text data was loaded.
|
|
109
|
+
*
|
|
110
|
+
* @remarks
|
|
111
|
+
* If a text data has already been loaded, the function will ignore the
|
|
112
|
+
* postProcess parameter and directly return the text loaded previously.
|
|
113
|
+
* To load the same text with different postProcess parameters,
|
|
114
|
+
* use different AssetManager instances separately.
|
|
115
|
+
*
|
|
116
|
+
* @returns The fetched text
|
|
118
117
|
*/ async fetchTextData(url, postProcess) {
|
|
119
118
|
let P = this._textDatas[url];
|
|
120
119
|
if (!P) {
|
|
@@ -123,18 +122,18 @@ import { TGALoader } from './loaders/image/tga_Loader.js';
|
|
|
123
122
|
}
|
|
124
123
|
return P;
|
|
125
124
|
}
|
|
126
|
-
/**
|
|
127
|
-
* Fetches a binary resource from a given URL
|
|
128
|
-
* @param url - The URL from where to fetch the resource
|
|
129
|
-
* @param postProcess - A function that will be involved when the binary data was loaded.
|
|
130
|
-
*
|
|
131
|
-
* @remarks
|
|
132
|
-
* If a binary data has already been loaded, the function will ignore the
|
|
133
|
-
* postProcess parameter and directly return the data loaded previously.
|
|
134
|
-
* To load the same data with different postProcess parameters,
|
|
135
|
-
* use different AssetManager instances separately.
|
|
136
|
-
*
|
|
137
|
-
* @returns Binary data as ArrayBuffer
|
|
125
|
+
/**
|
|
126
|
+
* Fetches a binary resource from a given URL
|
|
127
|
+
* @param url - The URL from where to fetch the resource
|
|
128
|
+
* @param postProcess - A function that will be involved when the binary data was loaded.
|
|
129
|
+
*
|
|
130
|
+
* @remarks
|
|
131
|
+
* If a binary data has already been loaded, the function will ignore the
|
|
132
|
+
* postProcess parameter and directly return the data loaded previously.
|
|
133
|
+
* To load the same data with different postProcess parameters,
|
|
134
|
+
* use different AssetManager instances separately.
|
|
135
|
+
*
|
|
136
|
+
* @returns Binary data as ArrayBuffer
|
|
138
137
|
*/ async fetchBinaryData(url, postProcess) {
|
|
139
138
|
let P = this._binaryDatas[url];
|
|
140
139
|
if (!P) {
|
|
@@ -143,11 +142,11 @@ import { TGALoader } from './loaders/image/tga_Loader.js';
|
|
|
143
142
|
}
|
|
144
143
|
return P;
|
|
145
144
|
}
|
|
146
|
-
/**
|
|
147
|
-
* Fetches a texture resource from a given URL
|
|
148
|
-
* @param url - The URL from where to fetch the resource
|
|
149
|
-
* @param options - Options for texture fetching
|
|
150
|
-
* @returns The fetched texture
|
|
145
|
+
/**
|
|
146
|
+
* Fetches a texture resource from a given URL
|
|
147
|
+
* @param url - The URL from where to fetch the resource
|
|
148
|
+
* @param options - Options for texture fetching
|
|
149
|
+
* @returns The fetched texture
|
|
151
150
|
*/ async fetchTexture(url, options) {
|
|
152
151
|
if (options?.texture) {
|
|
153
152
|
return this.loadTexture(url, options.mimeType ?? null, !options.linearColorSpace, options.samplerOptions, options.texture);
|
|
@@ -175,23 +174,22 @@ import { TGALoader } from './loaders/image/tga_Loader.js';
|
|
|
175
174
|
}
|
|
176
175
|
return P;
|
|
177
176
|
}
|
|
178
|
-
/**
|
|
179
|
-
* Fetches a model resource from a given URL and adds it to a scene
|
|
180
|
-
* @param scene - The scene to which the model node belongs
|
|
181
|
-
* @param url - The URL from where to fetch the resource
|
|
182
|
-
* @param
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
return this.createSceneNode(scene, sharedModel);
|
|
177
|
+
/**
|
|
178
|
+
* Fetches a model resource from a given URL and adds it to a scene
|
|
179
|
+
* @param scene - The scene to which the model node belongs
|
|
180
|
+
* @param url - The URL from where to fetch the resource
|
|
181
|
+
* @param options - Options for model fetching
|
|
182
|
+
*
|
|
183
|
+
* @remarks
|
|
184
|
+
* If a model has already been loaded, the function will ignore the
|
|
185
|
+
* postProcess parameter and directly return the model loaded previously.
|
|
186
|
+
* To load the same model with different postProcess parameters,
|
|
187
|
+
* use different AssetManager instances separately.
|
|
188
|
+
*
|
|
189
|
+
* @returns The created model node
|
|
190
|
+
*/ async fetchModel(scene, url, options) {
|
|
191
|
+
const sharedModel = await this.fetchModelData(scene, url, options?.mimeType, options?.postProcess);
|
|
192
|
+
return this.createSceneNode(scene, sharedModel, !options?.disableInstancing);
|
|
195
193
|
}
|
|
196
194
|
/** @internal */ async loadTextData(url, postProcess) {
|
|
197
195
|
let text = await this._httpRequest.requestText(url);
|
|
@@ -329,10 +327,10 @@ import { TGALoader } from './loaders/image/tga_Loader.js';
|
|
|
329
327
|
}
|
|
330
328
|
throw new Error(`Can not find loader for asset ${url}`);
|
|
331
329
|
}
|
|
332
|
-
/**
|
|
333
|
-
* Fetches a built-in texture
|
|
334
|
-
* @param name - Name of the built-in texture
|
|
335
|
-
* @returns The built-in texture
|
|
330
|
+
/**
|
|
331
|
+
* Fetches a built-in texture
|
|
332
|
+
* @param name - Name of the built-in texture
|
|
333
|
+
* @returns The built-in texture
|
|
336
334
|
*/ async fetchBuiltinTexture(name, texture) {
|
|
337
335
|
const loader = AssetManager._builtinTextureLoaders[name];
|
|
338
336
|
if (!loader) {
|
|
@@ -353,21 +351,16 @@ import { TGALoader } from './loaders/image/tga_Loader.js';
|
|
|
353
351
|
return tex;
|
|
354
352
|
}
|
|
355
353
|
}
|
|
356
|
-
/** @internal */ createSceneNode(scene, model,
|
|
354
|
+
/** @internal */ createSceneNode(scene, model, instancing) {
|
|
357
355
|
const group = new SceneNode(scene);
|
|
358
356
|
group.name = model.name;
|
|
359
357
|
let animationSet = new AnimationSet(scene);
|
|
360
358
|
for(let i = 0; i < model.scenes.length; i++){
|
|
361
|
-
if (typeof sceneIndex === 'number' && sceneIndex >= 0 && i !== sceneIndex) {
|
|
362
|
-
continue;
|
|
363
|
-
} else if ((sceneIndex === undefined || sceneIndex === null) && model.activeScene >= 0 && i !== model.activeScene) {
|
|
364
|
-
continue;
|
|
365
|
-
}
|
|
366
359
|
const assetScene = model.scenes[i];
|
|
367
360
|
const skeletonMeshMap = new Map();
|
|
368
361
|
const nodeMap = new Map();
|
|
369
362
|
for(let k = 0; k < assetScene.rootNodes.length; k++){
|
|
370
|
-
this.setAssetNodeToSceneNode(scene, group, model, assetScene.rootNodes[k], skeletonMeshMap, nodeMap);
|
|
363
|
+
this.setAssetNodeToSceneNode(scene, group, model, assetScene.rootNodes[k], skeletonMeshMap, nodeMap, instancing);
|
|
371
364
|
}
|
|
372
365
|
for (const animationData of model.animations){
|
|
373
366
|
const animation = new AnimationClip(animationData.name, group);
|
|
@@ -403,10 +396,10 @@ import { TGALoader } from './loaders/image/tga_Loader.js';
|
|
|
403
396
|
animationSet
|
|
404
397
|
};
|
|
405
398
|
}
|
|
406
|
-
/**
|
|
407
|
-
* Sets the loader for a given builtin-texture
|
|
408
|
-
* @param name - Name of the builtin texture
|
|
409
|
-
* @param loader - Loader for the builtin texture
|
|
399
|
+
/**
|
|
400
|
+
* Sets the loader for a given builtin-texture
|
|
401
|
+
* @param name - Name of the builtin texture
|
|
402
|
+
* @param loader - Loader for the builtin texture
|
|
410
403
|
*/ static setBuiltinTextureLoader(name, loader) {
|
|
411
404
|
if (loader) {
|
|
412
405
|
this._builtinTextureLoaders[name] = loader;
|
|
@@ -482,7 +475,7 @@ import { TGALoader } from './loaders/image/tga_Loader.js';
|
|
|
482
475
|
};
|
|
483
476
|
return info;
|
|
484
477
|
}
|
|
485
|
-
/** @internal */ setAssetNodeToSceneNode(scene, parent, model, assetNode, skeletonMeshMap, nodeMap) {
|
|
478
|
+
/** @internal */ setAssetNodeToSceneNode(scene, parent, model, assetNode, skeletonMeshMap, nodeMap, instancing) {
|
|
486
479
|
const node = new SceneNode(scene);
|
|
487
480
|
nodeMap.set(assetNode, node);
|
|
488
481
|
node.name = `${assetNode.name}`;
|
|
@@ -495,11 +488,10 @@ import { TGALoader } from './loaders/image/tga_Loader.js';
|
|
|
495
488
|
for (const subMesh of meshData.subMeshes){
|
|
496
489
|
const meshNode = new Mesh(scene);
|
|
497
490
|
meshNode.name = subMesh.name;
|
|
498
|
-
meshNode.
|
|
499
|
-
meshNode.showState =
|
|
500
|
-
meshNode.pickMode = GraphNode.PICK_INHERITED;
|
|
491
|
+
meshNode.clipTestEnabled = true;
|
|
492
|
+
meshNode.showState = 'inherit';
|
|
501
493
|
meshNode.primitive = subMesh.primitive;
|
|
502
|
-
meshNode.material = subMesh.material;
|
|
494
|
+
meshNode.material = instancing ? subMesh.material.createInstance() : subMesh.material;
|
|
503
495
|
// meshNode.drawBoundingBox = true;
|
|
504
496
|
meshNode.reparent(node);
|
|
505
497
|
if (skeleton) {
|
|
@@ -521,7 +513,7 @@ import { TGALoader } from './loaders/image/tga_Loader.js';
|
|
|
521
513
|
}
|
|
522
514
|
node.reparent(parent);
|
|
523
515
|
for (const child of assetNode.children){
|
|
524
|
-
this.setAssetNodeToSceneNode(scene, node, model, child, skeletonMeshMap, nodeMap);
|
|
516
|
+
this.setAssetNodeToSceneNode(scene, node, model, child, skeletonMeshMap, nodeMap, instancing);
|
|
525
517
|
}
|
|
526
518
|
}
|
|
527
519
|
getHash(type, url, options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assetmanager.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"assetmanager.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/camera/camera.js
CHANGED
|
@@ -12,6 +12,7 @@ import '../material/grassmaterial.js';
|
|
|
12
12
|
import '../material/terrainmaterial.js';
|
|
13
13
|
import '../material/pbrmr.js';
|
|
14
14
|
import '../material/pbrsg.js';
|
|
15
|
+
import '@zephyr3d/device';
|
|
15
16
|
import { SceneRenderer } from '../render/renderer.js';
|
|
16
17
|
import '../render/sky.js';
|
|
17
18
|
import '../render/clipmap.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"camera.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"camera.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|