@zephyr3d/scene 0.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/dist/animation/animation.js +173 -0
- package/dist/animation/animation.js.map +1 -0
- package/dist/animation/animationset.js +95 -0
- package/dist/animation/animationset.js.map +1 -0
- package/dist/animation/animationtrack.js +38 -0
- package/dist/animation/animationtrack.js.map +1 -0
- package/dist/animation/eulerrotationtrack.js +33 -0
- package/dist/animation/eulerrotationtrack.js.map +1 -0
- package/dist/animation/rotationtrack.js +37 -0
- package/dist/animation/rotationtrack.js.map +1 -0
- package/dist/animation/scaletrack.js +36 -0
- package/dist/animation/scaletrack.js.map +1 -0
- package/dist/animation/skeleton.js +97 -0
- package/dist/animation/skeleton.js.map +1 -0
- package/dist/animation/translationtrack.js +36 -0
- package/dist/animation/translationtrack.js.map +1 -0
- package/dist/animation/usertrack.js +47 -0
- package/dist/animation/usertrack.js.map +1 -0
- package/dist/app.js +173 -0
- package/dist/app.js.map +1 -0
- package/dist/asset/assetmanager.js +476 -0
- package/dist/asset/assetmanager.js.map +1 -0
- package/dist/asset/builtin.js +373 -0
- package/dist/asset/builtin.js.map +1 -0
- package/dist/asset/loaders/dds/dds.js +472 -0
- package/dist/asset/loaders/dds/dds.js.map +1 -0
- package/dist/asset/loaders/dds/dds_loader.js +38 -0
- package/dist/asset/loaders/dds/dds_loader.js.map +1 -0
- package/dist/asset/loaders/gltf/gltf_loader.js +981 -0
- package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -0
- package/dist/asset/loaders/gltf/helpers.js +314 -0
- package/dist/asset/loaders/gltf/helpers.js.map +1 -0
- package/dist/asset/loaders/hdr/hdr.js +175 -0
- package/dist/asset/loaders/hdr/hdr.js.map +1 -0
- package/dist/asset/loaders/image/tga_Loader.js +117 -0
- package/dist/asset/loaders/image/tga_Loader.js.map +1 -0
- package/dist/asset/loaders/image/webimage_loader.js +50 -0
- package/dist/asset/loaders/image/webimage_loader.js.map +1 -0
- package/dist/asset/loaders/loader.js +45 -0
- package/dist/asset/loaders/loader.js.map +1 -0
- package/dist/asset/model.js +264 -0
- package/dist/asset/model.js.map +1 -0
- package/dist/blitter/blitter.js +389 -0
- package/dist/blitter/blitter.js.map +1 -0
- package/dist/blitter/box.js +118 -0
- package/dist/blitter/box.js.map +1 -0
- package/dist/blitter/copy.js +22 -0
- package/dist/blitter/copy.js.map +1 -0
- package/dist/blitter/depthlimitedgaussion.js +166 -0
- package/dist/blitter/depthlimitedgaussion.js.map +1 -0
- package/dist/blitter/gaussianblur.js +229 -0
- package/dist/blitter/gaussianblur.js.map +1 -0
- package/dist/camera/base.js +90 -0
- package/dist/camera/base.js.map +1 -0
- package/dist/camera/camera.js +358 -0
- package/dist/camera/camera.js.map +1 -0
- package/dist/camera/fps.js +246 -0
- package/dist/camera/fps.js.map +1 -0
- package/dist/camera/orbit.js +157 -0
- package/dist/camera/orbit.js.map +1 -0
- package/dist/camera/orthocamera.js +126 -0
- package/dist/camera/orthocamera.js.map +1 -0
- package/dist/camera/perspectivecamera.js +133 -0
- package/dist/camera/perspectivecamera.js.map +1 -0
- package/dist/index.d.ts +8402 -0
- package/dist/index.js +87 -0
- package/dist/index.js.map +1 -0
- package/dist/input/inputmgr.js +242 -0
- package/dist/input/inputmgr.js.map +1 -0
- package/dist/material/blinn.js +75 -0
- package/dist/material/blinn.js.map +1 -0
- package/dist/material/grassmaterial.js +221 -0
- package/dist/material/grassmaterial.js.map +1 -0
- package/dist/material/lambert.js +52 -0
- package/dist/material/lambert.js.map +1 -0
- package/dist/material/lightmodel.js +2074 -0
- package/dist/material/lightmodel.js.map +1 -0
- package/dist/material/lit.js +578 -0
- package/dist/material/lit.js.map +1 -0
- package/dist/material/material.js +458 -0
- package/dist/material/material.js.map +1 -0
- package/dist/material/meshmaterial.js +311 -0
- package/dist/material/meshmaterial.js.map +1 -0
- package/dist/material/mixins/albedocolor.js +130 -0
- package/dist/material/mixins/albedocolor.js.map +1 -0
- package/dist/material/mixins/texture.js +110 -0
- package/dist/material/mixins/texture.js.map +1 -0
- package/dist/material/mixins/vertexcolor.js +45 -0
- package/dist/material/mixins/vertexcolor.js.map +1 -0
- package/dist/material/pbr.js +27 -0
- package/dist/material/pbr.js.map +1 -0
- package/dist/material/standard.js +282 -0
- package/dist/material/standard.js.map +1 -0
- package/dist/material/terrainlightmodel.js +259 -0
- package/dist/material/terrainlightmodel.js.map +1 -0
- package/dist/material/terrainmaterial.js +139 -0
- package/dist/material/terrainmaterial.js.map +1 -0
- package/dist/material/unlit.js +29 -0
- package/dist/material/unlit.js.map +1 -0
- package/dist/posteffect/bloom.js +398 -0
- package/dist/posteffect/bloom.js.map +1 -0
- package/dist/posteffect/compositor.js +264 -0
- package/dist/posteffect/compositor.js.map +1 -0
- package/dist/posteffect/fxaa.js +291 -0
- package/dist/posteffect/fxaa.js.map +1 -0
- package/dist/posteffect/grayscale.js +87 -0
- package/dist/posteffect/grayscale.js.map +1 -0
- package/dist/posteffect/posteffect.js +165 -0
- package/dist/posteffect/posteffect.js.map +1 -0
- package/dist/posteffect/sao.js +327 -0
- package/dist/posteffect/sao.js.map +1 -0
- package/dist/posteffect/tonemap.js +112 -0
- package/dist/posteffect/tonemap.js.map +1 -0
- package/dist/posteffect/water.js +535 -0
- package/dist/posteffect/water.js.map +1 -0
- package/dist/render/clipmap.js +462 -0
- package/dist/render/clipmap.js.map +1 -0
- package/dist/render/cluster_light.js +329 -0
- package/dist/render/cluster_light.js.map +1 -0
- package/dist/render/cull_visitor.js +124 -0
- package/dist/render/cull_visitor.js.map +1 -0
- package/dist/render/depth_pass.js +47 -0
- package/dist/render/depth_pass.js.map +1 -0
- package/dist/render/envlight.js +282 -0
- package/dist/render/envlight.js.map +1 -0
- package/dist/render/forward.js +186 -0
- package/dist/render/forward.js.map +1 -0
- package/dist/render/forward_pass.js +137 -0
- package/dist/render/forward_pass.js.map +1 -0
- package/dist/render/helper.js +38 -0
- package/dist/render/helper.js.map +1 -0
- package/dist/render/primitive.js +246 -0
- package/dist/render/primitive.js.map +1 -0
- package/dist/render/render_queue.js +163 -0
- package/dist/render/render_queue.js.map +1 -0
- package/dist/render/renderpass.js +151 -0
- package/dist/render/renderpass.js.map +1 -0
- package/dist/render/renderscheme.js +61 -0
- package/dist/render/renderscheme.js.map +1 -0
- package/dist/render/scatteringlut.js +634 -0
- package/dist/render/scatteringlut.js.map +1 -0
- package/dist/render/shadowmap_pass.js +70 -0
- package/dist/render/shadowmap_pass.js.map +1 -0
- package/dist/render/sky.js +881 -0
- package/dist/render/sky.js.map +1 -0
- package/dist/render/temporalcache.js +222 -0
- package/dist/render/temporalcache.js.map +1 -0
- package/dist/render/watermesh.js +835 -0
- package/dist/render/watermesh.js.map +1 -0
- package/dist/scene/environment.js +146 -0
- package/dist/scene/environment.js.map +1 -0
- package/dist/scene/graph_node.js +69 -0
- package/dist/scene/graph_node.js.map +1 -0
- package/dist/scene/light.js +436 -0
- package/dist/scene/light.js.map +1 -0
- package/dist/scene/mesh.js +215 -0
- package/dist/scene/mesh.js.map +1 -0
- package/dist/scene/model.js +111 -0
- package/dist/scene/model.js.map +1 -0
- package/dist/scene/octree.js +651 -0
- package/dist/scene/octree.js.map +1 -0
- package/dist/scene/octree_update_visitor.js +16 -0
- package/dist/scene/octree_update_visitor.js.map +1 -0
- package/dist/scene/raycast_visitor.js +72 -0
- package/dist/scene/raycast_visitor.js.map +1 -0
- package/dist/scene/scene.js +225 -0
- package/dist/scene/scene.js.map +1 -0
- package/dist/scene/scene_node.js +299 -0
- package/dist/scene/scene_node.js.map +1 -0
- package/dist/scene/terrain/grass.js +277 -0
- package/dist/scene/terrain/grass.js.map +1 -0
- package/dist/scene/terrain/heightfield.js +391 -0
- package/dist/scene/terrain/heightfield.js.map +1 -0
- package/dist/scene/terrain/patch.js +530 -0
- package/dist/scene/terrain/patch.js.map +1 -0
- package/dist/scene/terrain/quadtree.js +430 -0
- package/dist/scene/terrain/quadtree.js.map +1 -0
- package/dist/scene/terrain/terrain.js +258 -0
- package/dist/scene/terrain/terrain.js.map +1 -0
- package/dist/scene/xform.js +224 -0
- package/dist/scene/xform.js.map +1 -0
- package/dist/shaders/builtins.js +110 -0
- package/dist/shaders/builtins.js.map +1 -0
- package/dist/shaders/framework.js +709 -0
- package/dist/shaders/framework.js.map +1 -0
- package/dist/shaders/lighting.js +335 -0
- package/dist/shaders/lighting.js.map +1 -0
- package/dist/shaders/misc.js +405 -0
- package/dist/shaders/misc.js.map +1 -0
- package/dist/shaders/noise.js +157 -0
- package/dist/shaders/noise.js.map +1 -0
- package/dist/shaders/pbr.js +132 -0
- package/dist/shaders/pbr.js.map +1 -0
- package/dist/shaders/shadow.js +642 -0
- package/dist/shaders/shadow.js.map +1 -0
- package/dist/shaders/water.js +630 -0
- package/dist/shaders/water.js.map +1 -0
- package/dist/shadow/esm.js +235 -0
- package/dist/shadow/esm.js.map +1 -0
- package/dist/shadow/pcf_opt.js +182 -0
- package/dist/shadow/pcf_opt.js.map +1 -0
- package/dist/shadow/pcf_pd.js +190 -0
- package/dist/shadow/pcf_pd.js.map +1 -0
- package/dist/shadow/shadow_impl.js +15 -0
- package/dist/shadow/shadow_impl.js.map +1 -0
- package/dist/shadow/shadowmapper.js +709 -0
- package/dist/shadow/shadowmapper.js.map +1 -0
- package/dist/shadow/ssm.js +194 -0
- package/dist/shadow/ssm.js.map +1 -0
- package/dist/shadow/vsm.js +298 -0
- package/dist/shadow/vsm.js.map +1 -0
- package/dist/shapes/box.js +313 -0
- package/dist/shapes/box.js.map +1 -0
- package/dist/shapes/cylinder.js +74 -0
- package/dist/shapes/cylinder.js.map +1 -0
- package/dist/shapes/plane.js +48 -0
- package/dist/shapes/plane.js.map +1 -0
- package/dist/shapes/shape.js +33 -0
- package/dist/shapes/shape.js.map +1 -0
- package/dist/shapes/sphere.js +91 -0
- package/dist/shapes/sphere.js.map +1 -0
- package/dist/shapes/torus.js +100 -0
- package/dist/shapes/torus.js.map +1 -0
- package/dist/utility/aabbtree.js +390 -0
- package/dist/utility/aabbtree.js.map +1 -0
- package/dist/utility/bounding_volume.js +78 -0
- package/dist/utility/bounding_volume.js.map +1 -0
- package/dist/utility/panorama.js +163 -0
- package/dist/utility/panorama.js.map +1 -0
- package/dist/utility/pmrem.js +345 -0
- package/dist/utility/pmrem.js.map +1 -0
- package/dist/utility/shprojection.js +448 -0
- package/dist/utility/shprojection.js.map +1 -0
- package/dist/values.js +48 -0
- package/dist/values.js.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { Application } from '../app.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Primitive contains only the vertex and index data of a mesh
|
|
5
|
+
* @public
|
|
6
|
+
*/ class Primitive {
|
|
7
|
+
/** @internal */ _vertexLayout;
|
|
8
|
+
/** @internal */ _vertexLayoutOptions;
|
|
9
|
+
/** @internal */ _primitiveType;
|
|
10
|
+
/** @internal */ _indexStart;
|
|
11
|
+
/** @internal */ _indexCount;
|
|
12
|
+
/** @internal */ _defaultIndexCount;
|
|
13
|
+
/** @internal */ _vertexLayoutDirty;
|
|
14
|
+
/** @internal */ static _nextId = 0;
|
|
15
|
+
/** @internal */ _id;
|
|
16
|
+
/** @internal */ _bbox;
|
|
17
|
+
/** @internal */ _bboxChangeCallback;
|
|
18
|
+
/**
|
|
19
|
+
* Creates an instance of a primitive
|
|
20
|
+
*/ constructor(){
|
|
21
|
+
this._vertexLayout = null;
|
|
22
|
+
this._vertexLayoutOptions = {
|
|
23
|
+
vertexBuffers: []
|
|
24
|
+
};
|
|
25
|
+
this._primitiveType = 'triangle-list';
|
|
26
|
+
this._indexStart = 0;
|
|
27
|
+
this._indexCount = null;
|
|
28
|
+
this._defaultIndexCount = 0;
|
|
29
|
+
this._vertexLayoutDirty = false;
|
|
30
|
+
this._id = ++Primitive._nextId;
|
|
31
|
+
this._bbox = null;
|
|
32
|
+
this._bboxChangeCallback = [];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Unique identifier of the primitive
|
|
36
|
+
* @internal
|
|
37
|
+
*/ get id() {
|
|
38
|
+
return this._id;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Adds a callback function that will be called whenever the bounding box of the primitive changes.
|
|
42
|
+
* @param cb - The callback function
|
|
43
|
+
*
|
|
44
|
+
* @internal
|
|
45
|
+
*/ addBoundingboxChangeCallback(cb) {
|
|
46
|
+
cb && this._bboxChangeCallback.push(cb);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Removes a callback function for bounding box changing
|
|
50
|
+
* @param cb - The callback function to be removed
|
|
51
|
+
*/ removeBoundingboxChangeCallback(cb) {
|
|
52
|
+
const index = this._bboxChangeCallback.indexOf(cb);
|
|
53
|
+
if (index >= 0) {
|
|
54
|
+
this._bboxChangeCallback.splice(index, 1);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** Primitive type */ get primitiveType() {
|
|
58
|
+
return this._primitiveType;
|
|
59
|
+
}
|
|
60
|
+
set primitiveType(type) {
|
|
61
|
+
this._primitiveType = type;
|
|
62
|
+
}
|
|
63
|
+
/** Start index for drawing */ get indexStart() {
|
|
64
|
+
return this._indexStart;
|
|
65
|
+
}
|
|
66
|
+
set indexStart(val) {
|
|
67
|
+
this._indexStart = val;
|
|
68
|
+
}
|
|
69
|
+
/** The number of the indices or vertices to be drawn */ get indexCount() {
|
|
70
|
+
this._indexCount = this._indexCount ?? this.calcDefaultIndexCount();
|
|
71
|
+
return this._indexCount;
|
|
72
|
+
}
|
|
73
|
+
set indexCount(val) {
|
|
74
|
+
this._indexCount = val;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Removes a vertex buffer from the primitive
|
|
78
|
+
* @param buffer - The vertex buffer to be removed
|
|
79
|
+
*/ removeVertexBuffer(buffer) {
|
|
80
|
+
for(let loc = 0; loc < this._vertexLayoutOptions.vertexBuffers.length; loc++){
|
|
81
|
+
const info = this._vertexLayoutOptions.vertexBuffers[loc];
|
|
82
|
+
if (info?.buffer === buffer) {
|
|
83
|
+
info[loc] = null;
|
|
84
|
+
this._vertexLayoutDirty = true;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Gets the vertex buffer by a given semantic
|
|
90
|
+
* @param semantic - The semantic of the vertex buffer
|
|
91
|
+
* @returns The vertex buffer which semantic matches the given value
|
|
92
|
+
*/ getVertexBuffer(semantic) {
|
|
93
|
+
this.checkVertexLayout();
|
|
94
|
+
return this._vertexLayout.getVertexBuffer(semantic);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Gets the vertex buffer information by a given semantic
|
|
98
|
+
* @param semantic - The semantic of the vertex buffer
|
|
99
|
+
* @returns The vertex buffer information of the given semantic
|
|
100
|
+
*/ getVertexBufferInfo(semantic) {
|
|
101
|
+
this.checkVertexLayout();
|
|
102
|
+
return this._vertexLayout.getVertexBufferInfo(semantic);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Creates a vertex buffer from the given options and then adds it to the primitive
|
|
106
|
+
* @param format - Vertex format for the vertex buffer
|
|
107
|
+
* @param data - Contents of the vertex buffer
|
|
108
|
+
* @param stepMode - Step mode of the vertex buffer
|
|
109
|
+
* @returns The created vertex buffer
|
|
110
|
+
*/ createAndSetVertexBuffer(format, data, stepMode) {
|
|
111
|
+
const buffer = Application.instance.device.createVertexBuffer(format, data);
|
|
112
|
+
return this.setVertexBuffer(buffer, stepMode);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Adds a vertex buffer to the primitive
|
|
116
|
+
* @param buffer - The vertex buffer to be added
|
|
117
|
+
* @param stepMode - Step mode of the vertex buffer
|
|
118
|
+
* @returns The added vertex buffer
|
|
119
|
+
*/ setVertexBuffer(buffer, stepMode) {
|
|
120
|
+
this._vertexLayoutOptions.vertexBuffers.push({
|
|
121
|
+
buffer,
|
|
122
|
+
stepMode
|
|
123
|
+
});
|
|
124
|
+
this._vertexLayoutDirty = true;
|
|
125
|
+
return buffer;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Creates an index buffer from the given options and then adds it to the prmitive
|
|
129
|
+
* @param data - Contents of the index buffer
|
|
130
|
+
* @param dynamic - true if the index buffer is dynamic
|
|
131
|
+
* @returns The created index buffer
|
|
132
|
+
*/ createAndSetIndexBuffer(data, dynamic) {
|
|
133
|
+
const buffer = Application.instance.device.createIndexBuffer(data, {
|
|
134
|
+
dynamic: !!dynamic,
|
|
135
|
+
managed: !dynamic
|
|
136
|
+
});
|
|
137
|
+
this.setIndexBuffer(buffer);
|
|
138
|
+
return buffer;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Adds an index buffer to the primitive
|
|
142
|
+
* @param buffer - The index buffer to be added
|
|
143
|
+
*/ setIndexBuffer(buffer) {
|
|
144
|
+
if (this._vertexLayoutOptions.indexBuffer !== buffer) {
|
|
145
|
+
this._vertexLayoutOptions.indexBuffer = buffer;
|
|
146
|
+
this._vertexLayoutDirty = true;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Gets the index buffer of the primitive
|
|
151
|
+
* @returns The index buffer of the primitive
|
|
152
|
+
*/ getIndexBuffer() {
|
|
153
|
+
return this._vertexLayoutOptions.indexBuffer;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Draw the prmitive
|
|
157
|
+
*/ draw() {
|
|
158
|
+
this.checkVertexLayout();
|
|
159
|
+
if (this.indexCount > 0) {
|
|
160
|
+
this._vertexLayout?.draw(this._primitiveType, this._indexStart, this.indexCount);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Draw multiple instances of the primitive
|
|
165
|
+
* @param numInstances - How many instances of the primitive should be drawn
|
|
166
|
+
*/ drawInstanced(numInstances) {
|
|
167
|
+
this.checkVertexLayout();
|
|
168
|
+
if (this.indexCount > 0) {
|
|
169
|
+
this._vertexLayout?.drawInstanced(this._primitiveType, this._indexStart, this.indexCount, numInstances);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Disposes the primitive
|
|
174
|
+
*
|
|
175
|
+
* @remarks
|
|
176
|
+
* The vertex buffers and index buffer will also be disposed.
|
|
177
|
+
* To prevent specific vertex buffer or index buffer to be disposed,
|
|
178
|
+
* call removeVertexBuffer() or setIndexBuffer(null) first.
|
|
179
|
+
*/ dispose() {
|
|
180
|
+
if (this._vertexLayout) {
|
|
181
|
+
const vertexBuffers = this._vertexLayout.vertexBuffers;
|
|
182
|
+
for(const k in vertexBuffers){
|
|
183
|
+
vertexBuffers[k]?.buffer?.dispose();
|
|
184
|
+
}
|
|
185
|
+
this._vertexLayout.indexBuffer?.dispose();
|
|
186
|
+
this._vertexLayout.dispose();
|
|
187
|
+
this._vertexLayout = null;
|
|
188
|
+
}
|
|
189
|
+
this._indexCount = null;
|
|
190
|
+
this._indexStart = 0;
|
|
191
|
+
}
|
|
192
|
+
/*
|
|
193
|
+
createAABBTree(): AABBTree {
|
|
194
|
+
const indices = this.getIndexBuffer() ? this.getIndexBuffer().getData() : null;
|
|
195
|
+
const vertices = (this.getVertexBuffer(VERTEX_ATTRIB_POSITION)?.getData() as Float32Array) || null;
|
|
196
|
+
const aabbtree = new AABBTree();
|
|
197
|
+
aabbtree.buildFromPrimitives(vertices, indices, this._primitiveType);
|
|
198
|
+
return aabbtree;
|
|
199
|
+
}
|
|
200
|
+
*/ /**
|
|
201
|
+
* Gets the bounding volume of the primitive
|
|
202
|
+
* @returns The bounding volume of the primitive, or null if no bounding volume set
|
|
203
|
+
*/ getBoundingVolume() {
|
|
204
|
+
return this._bbox;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Sets the bounding volume of the primitive
|
|
208
|
+
* @param bv - The bounding volume to be set
|
|
209
|
+
*/ setBoundingVolume(bv) {
|
|
210
|
+
if (bv !== this._bbox) {
|
|
211
|
+
this._bbox = bv;
|
|
212
|
+
for (const cb of this._bboxChangeCallback){
|
|
213
|
+
cb();
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Ray intersection test
|
|
219
|
+
* @param ray - Ray object used to do intersection test with this object
|
|
220
|
+
* @returns The distance from ray origin to the intersection point if ray intersects with this object, otherwise null
|
|
221
|
+
*/ raycast(ray) {
|
|
222
|
+
const aabb = this.getBoundingVolume()?.toAABB();
|
|
223
|
+
return aabb ? ray.bboxIntersectionTestEx(aabb) : null;
|
|
224
|
+
}
|
|
225
|
+
/** @internal */ checkVertexLayout() {
|
|
226
|
+
if (this._vertexLayoutDirty) {
|
|
227
|
+
this._vertexLayout?.dispose();
|
|
228
|
+
this._vertexLayout = Application.instance.device.createVertexLayout(this._vertexLayoutOptions);
|
|
229
|
+
this._vertexLayoutDirty = false;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/** @internal */ calcDefaultIndexCount() {
|
|
233
|
+
const indexBuffer = this.getIndexBuffer();
|
|
234
|
+
if (indexBuffer) {
|
|
235
|
+
return Math.max(0, indexBuffer.length - this._indexStart);
|
|
236
|
+
}
|
|
237
|
+
const info = this.getVertexBufferInfo('position');
|
|
238
|
+
if (info) {
|
|
239
|
+
return Math.max(0, Math.floor((info.buffer.byteLength - info.drawOffset) / info.stride) - this._indexStart);
|
|
240
|
+
}
|
|
241
|
+
return 0;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export { Primitive };
|
|
246
|
+
//# sourceMappingURL=primitive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"primitive.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { Application } from '../app.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A queue that contains the items to be rendered
|
|
5
|
+
* @public
|
|
6
|
+
*/ class RenderQueue {
|
|
7
|
+
/** @internal */ _itemLists;
|
|
8
|
+
/** @internal */ _renderPass;
|
|
9
|
+
/** @internal */ _shadowedLightList;
|
|
10
|
+
/** @internal */ _unshadowedLightList;
|
|
11
|
+
/** @internal */ _sunLight;
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of a render queue
|
|
14
|
+
* @param renderPass - The render pass to which the render queue belongs
|
|
15
|
+
*/ constructor(renderPass){
|
|
16
|
+
this._itemLists = {};
|
|
17
|
+
this._renderPass = renderPass;
|
|
18
|
+
this._shadowedLightList = [];
|
|
19
|
+
this._unshadowedLightList = [];
|
|
20
|
+
this._sunLight = null;
|
|
21
|
+
}
|
|
22
|
+
/** The sun light */ get sunLight() {
|
|
23
|
+
return this._sunLight;
|
|
24
|
+
}
|
|
25
|
+
set sunLight(light) {
|
|
26
|
+
this._sunLight = light;
|
|
27
|
+
}
|
|
28
|
+
/** The render pass to which the render queue belongs */ get renderPass() {
|
|
29
|
+
return this._renderPass;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Gets the items of the render queue
|
|
33
|
+
*/ get items() {
|
|
34
|
+
return this._itemLists;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Gets the shadowed lights
|
|
38
|
+
*/ get shadowedLights() {
|
|
39
|
+
return this._shadowedLightList;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Gets the unshadowed lights
|
|
43
|
+
*/ get unshadowedLights() {
|
|
44
|
+
return this._unshadowedLightList;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Gets the maximum batch size of a given device
|
|
48
|
+
* @returns The maximum batch size of the device
|
|
49
|
+
*
|
|
50
|
+
* @internal
|
|
51
|
+
*/ getMaxBatchSize() {
|
|
52
|
+
return Application.instance.device.getDeviceCaps().shaderCaps.maxUniformBufferSize / 64;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Push a punctual light
|
|
56
|
+
* @param light - The light to be pushed
|
|
57
|
+
*/ pushLight(light) {
|
|
58
|
+
if (light.castShadow) {
|
|
59
|
+
this._shadowedLightList.push(light);
|
|
60
|
+
} else {
|
|
61
|
+
this._unshadowedLightList.push(light);
|
|
62
|
+
}
|
|
63
|
+
if (light.isDirectionLight() && light.sunLight) {
|
|
64
|
+
this.sunLight = light;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Push an item to the render queue
|
|
69
|
+
* @param camera - The camera for drawing the item
|
|
70
|
+
* @param drawable - The object to be drawn
|
|
71
|
+
* @param renderOrder - Render order of the object
|
|
72
|
+
*/ push(camera, drawable, renderOrder) {
|
|
73
|
+
if (drawable) {
|
|
74
|
+
let itemList = this._itemLists[renderOrder];
|
|
75
|
+
if (!itemList) {
|
|
76
|
+
itemList = {
|
|
77
|
+
opaqueList: [],
|
|
78
|
+
opaqueInstanceList: {},
|
|
79
|
+
transList: [],
|
|
80
|
+
transInstanceList: {}
|
|
81
|
+
};
|
|
82
|
+
this._itemLists[renderOrder] = itemList;
|
|
83
|
+
}
|
|
84
|
+
const trans = drawable.isTransparency();
|
|
85
|
+
const list = trans ? itemList.transList : itemList.opaqueList;
|
|
86
|
+
if (drawable.isBatchable()) {
|
|
87
|
+
const instanceList = trans ? itemList.transInstanceList : itemList.opaqueInstanceList;
|
|
88
|
+
const hash = drawable.getInstanceId(this._renderPass);
|
|
89
|
+
const index = instanceList[hash];
|
|
90
|
+
if (index === undefined || list[index].instanceData.worldMatrices.length === this.getMaxBatchSize()) {
|
|
91
|
+
instanceList[hash] = list.length;
|
|
92
|
+
list.push({
|
|
93
|
+
drawable,
|
|
94
|
+
sortDistance: drawable.getSortDistance(camera),
|
|
95
|
+
instanceData: {
|
|
96
|
+
worldMatrices: [
|
|
97
|
+
drawable.getXForm().worldMatrix
|
|
98
|
+
],
|
|
99
|
+
hash: hash
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
} else {
|
|
103
|
+
list[index].instanceData.worldMatrices.push(drawable.getXForm().worldMatrix);
|
|
104
|
+
}
|
|
105
|
+
} else {
|
|
106
|
+
list.push({
|
|
107
|
+
drawable,
|
|
108
|
+
sortDistance: drawable.getSortDistance(camera),
|
|
109
|
+
instanceData: null
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Removes all items in the render queue
|
|
116
|
+
*/ clear() {
|
|
117
|
+
this._itemLists = {};
|
|
118
|
+
this._shadowedLightList = [];
|
|
119
|
+
this._unshadowedLightList = [];
|
|
120
|
+
this._sunLight = null;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Sorts the items in the render queue for rendering
|
|
124
|
+
*/ sortItems() {
|
|
125
|
+
for (const list of Object.values(this._itemLists)){
|
|
126
|
+
list.opaqueList.sort((a, b)=>a.sortDistance - b.sortDistance);
|
|
127
|
+
list.transList.sort((a, b)=>b.sortDistance - a.sortDistance);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
encodeInstanceColor(index, outColor) {
|
|
131
|
+
outColor[0] = (index >> 24 & 255) / 255;
|
|
132
|
+
outColor[1] = (index >> 16 & 255) / 255;
|
|
133
|
+
outColor[2] = (index >> 8 && 255) / 255;
|
|
134
|
+
outColor[3] = (index >> 0 && 255) / 255;
|
|
135
|
+
}
|
|
136
|
+
/*
|
|
137
|
+
private decodeInstanceColor(value: Float32Array): number {
|
|
138
|
+
return (value[0] << 24) + (value[1] << 16) + (value[2] << 8) + value[3];
|
|
139
|
+
}
|
|
140
|
+
*/ setInstanceColors() {
|
|
141
|
+
const nodes = [];
|
|
142
|
+
let id = 0;
|
|
143
|
+
for(const k in this._itemLists){
|
|
144
|
+
const lists = this._itemLists[k];
|
|
145
|
+
for (const item of lists.opaqueList){
|
|
146
|
+
if (item.instanceColor) {
|
|
147
|
+
item.instanceData.instanceColorList = [];
|
|
148
|
+
for(let i = 0; i < item.instanceData.worldMatrices.length; i++){
|
|
149
|
+
const v = item.drawable.getInstanceColor();
|
|
150
|
+
this.encodeInstanceColor(id, v);
|
|
151
|
+
nodes[id] = item.drawable.getPickTarget();
|
|
152
|
+
item.instanceData.instanceColorList.push(v);
|
|
153
|
+
id++;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return nodes;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export { RenderQueue };
|
|
163
|
+
//# sourceMappingURL=render_queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render_queue.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { Vector4 } from '@zephyr3d/base';
|
|
2
|
+
import { CullVisitor } from './cull_visitor.js';
|
|
3
|
+
import { Material } from '../material/material.js';
|
|
4
|
+
import '@zephyr3d/device';
|
|
5
|
+
import { ShaderFramework } from '../shaders/framework.js';
|
|
6
|
+
import { Application } from '../app.js';
|
|
7
|
+
import './scatteringlut.js';
|
|
8
|
+
import '../material/lambert.js';
|
|
9
|
+
import '../material/blinn.js';
|
|
10
|
+
import '../material/unlit.js';
|
|
11
|
+
import '../material/lightmodel.js';
|
|
12
|
+
import { RenderQueue } from './render_queue.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Base class for any kind of render passes
|
|
16
|
+
* @public
|
|
17
|
+
*/ class RenderPass {
|
|
18
|
+
/** @internal */ _type;
|
|
19
|
+
/** @internal */ _globalBindGroups;
|
|
20
|
+
/** @internal */ _clearColor;
|
|
21
|
+
/** @internal */ _clearDepth;
|
|
22
|
+
/** @internal */ _clearStencil;
|
|
23
|
+
/**
|
|
24
|
+
* Creates an instanceof RenderPass
|
|
25
|
+
* @param type - Render pass type
|
|
26
|
+
*/ constructor(type){
|
|
27
|
+
this._type = type;
|
|
28
|
+
this._clearColor = new Vector4(0, 0, 0, 1);
|
|
29
|
+
this._clearDepth = 1;
|
|
30
|
+
this._clearStencil = 0;
|
|
31
|
+
this._globalBindGroups = {};
|
|
32
|
+
}
|
|
33
|
+
/** Color value that is used to clear the frame buffer */ get clearColor() {
|
|
34
|
+
return this._clearColor;
|
|
35
|
+
}
|
|
36
|
+
set clearColor(color) {
|
|
37
|
+
this._clearColor = color ?? null;
|
|
38
|
+
}
|
|
39
|
+
/** Depth value that is used to clear the frame buffer */ get clearDepth() {
|
|
40
|
+
return this._clearDepth;
|
|
41
|
+
}
|
|
42
|
+
set clearDepth(depth) {
|
|
43
|
+
this._clearDepth = depth ?? null;
|
|
44
|
+
}
|
|
45
|
+
/** Stencil value that is used to clear the frame buffer */ get clearStencil() {
|
|
46
|
+
return this._clearStencil;
|
|
47
|
+
}
|
|
48
|
+
set clearStencil(stencil) {
|
|
49
|
+
this._clearStencil = stencil ?? null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The render pass type
|
|
53
|
+
*/ get type() {
|
|
54
|
+
return this._type;
|
|
55
|
+
}
|
|
56
|
+
/** @internal */ isAutoFlip() {
|
|
57
|
+
return !!(Application.instance.device.getFramebuffer() && Application.instance.device.type === 'webgpu');
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Renders a scene
|
|
61
|
+
* @param ctx - Drawing context
|
|
62
|
+
*/ render(ctx, cullCamera, renderQueue) {
|
|
63
|
+
ctx.renderPass = this;
|
|
64
|
+
this.drawScene(ctx, cullCamera ?? ctx.camera, renderQueue);
|
|
65
|
+
}
|
|
66
|
+
/** @internal */ applyRenderStates(device, stateSet, ctx) {
|
|
67
|
+
device.setRenderStates(stateSet);
|
|
68
|
+
}
|
|
69
|
+
/** @internal */ getGlobalBindGroupInfo(ctx) {
|
|
70
|
+
const hash = this.getGlobalBindGroupHash(ctx);
|
|
71
|
+
let bindGroup = this._globalBindGroups[hash];
|
|
72
|
+
if (!bindGroup) {
|
|
73
|
+
//const programBuilder = new ProgramBuilder(Application.instance.device);
|
|
74
|
+
const ret = Application.instance.device.programBuilder.buildRender({
|
|
75
|
+
vertex (pb) {
|
|
76
|
+
ShaderFramework.prepareVertexShader(pb, ctx);
|
|
77
|
+
pb.main(function() {});
|
|
78
|
+
},
|
|
79
|
+
fragment (pb) {
|
|
80
|
+
ShaderFramework.prepareFragmentShader(pb, ctx);
|
|
81
|
+
pb.main(function() {});
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
bindGroup = {
|
|
85
|
+
bindGroup: Application.instance.device.createBindGroup(ret[2][0]),
|
|
86
|
+
layout: ret[2][0]
|
|
87
|
+
};
|
|
88
|
+
this._globalBindGroups[hash] = bindGroup;
|
|
89
|
+
}
|
|
90
|
+
if (bindGroup.bindGroup.disposed) {
|
|
91
|
+
bindGroup.bindGroup.reload();
|
|
92
|
+
}
|
|
93
|
+
return bindGroup;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Disposes the render pass
|
|
97
|
+
*/ dispose() {
|
|
98
|
+
for(const k in this._globalBindGroups){
|
|
99
|
+
Material.bindGroupGarbageCollect(this._globalBindGroups[k].bindGroup);
|
|
100
|
+
}
|
|
101
|
+
this._globalBindGroups = {};
|
|
102
|
+
}
|
|
103
|
+
/** @internal */ getGlobalBindGroupHash(ctx) {
|
|
104
|
+
return `${this.constructor.name}:${this._getGlobalBindGroupHash(ctx)}`;
|
|
105
|
+
}
|
|
106
|
+
/** @internal */ drawScene(ctx, cullCamera, renderQueue) {
|
|
107
|
+
const device = Application.instance.device;
|
|
108
|
+
this.clearFramebuffer();
|
|
109
|
+
renderQueue = renderQueue ?? this.cullScene(ctx, cullCamera);
|
|
110
|
+
if (renderQueue) {
|
|
111
|
+
const windingReversed = device.isWindingOrderReversed();
|
|
112
|
+
device.reverseVertexWindingOrder(this.isAutoFlip() ? !windingReversed : windingReversed);
|
|
113
|
+
this.renderItems(ctx, renderQueue);
|
|
114
|
+
device.reverseVertexWindingOrder(windingReversed);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Culls a scene by a given camera
|
|
119
|
+
* @param ctx - The draw context
|
|
120
|
+
* @param cullCamera - The camera that will be used to cull the scene
|
|
121
|
+
* @returns The cull result
|
|
122
|
+
*/ cullScene(ctx, cullCamera) {
|
|
123
|
+
if (cullCamera) {
|
|
124
|
+
const renderQueue = new RenderQueue(this);
|
|
125
|
+
const cullVisitor = new CullVisitor(this, cullCamera, renderQueue, ctx.primaryCamera);
|
|
126
|
+
if (ctx.scene.octree) {
|
|
127
|
+
ctx.scene.octree.getRootNode().traverse(cullVisitor);
|
|
128
|
+
} else {
|
|
129
|
+
ctx.scene.rootNode.traverse(cullVisitor);
|
|
130
|
+
}
|
|
131
|
+
return renderQueue;
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
/** @internal */ drawItem(device, item, ctx, reverseWinding) {
|
|
136
|
+
const reverse = reverseWinding !== item.drawable.getXForm().worldMatrixDet < 0;
|
|
137
|
+
if (reverse) {
|
|
138
|
+
device.reverseVertexWindingOrder(!device.isWindingOrderReversed());
|
|
139
|
+
}
|
|
140
|
+
item.drawable.draw(ctx);
|
|
141
|
+
if (reverse) {
|
|
142
|
+
device.reverseVertexWindingOrder(!device.isWindingOrderReversed());
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/** @internal */ clearFramebuffer() {
|
|
146
|
+
Application.instance.device.clearFrameBuffer(this._clearColor, this._clearDepth, this._clearStencil);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export { RenderPass };
|
|
151
|
+
//# sourceMappingURL=renderpass.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderpass.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Application } from '../app.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Base class for any kind of render scheme
|
|
5
|
+
* @public
|
|
6
|
+
*/ class RenderScheme {
|
|
7
|
+
/** @internal */ _shadowMapFormat;
|
|
8
|
+
/** @internal */ _enableDepthPass;
|
|
9
|
+
/** @internal */ _currentScene;
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of RenderScheme
|
|
12
|
+
*/ constructor(){
|
|
13
|
+
this._shadowMapFormat = null;
|
|
14
|
+
this._enableDepthPass = false;
|
|
15
|
+
this._currentScene = null;
|
|
16
|
+
}
|
|
17
|
+
/** True if an early depth pass is required */ get requireDepthPass() {
|
|
18
|
+
return this._enableDepthPass;
|
|
19
|
+
}
|
|
20
|
+
set requireDepthPass(val) {
|
|
21
|
+
this._enableDepthPass = !!val;
|
|
22
|
+
}
|
|
23
|
+
/** The scene that is currently been rendered */ get currentScene() {
|
|
24
|
+
return this._currentScene;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Renders a scene by given camera
|
|
28
|
+
* @param scene - The scene to be rendered
|
|
29
|
+
* @param camera - The camera that will be used to render the scene
|
|
30
|
+
*/ renderScene(scene, camera, compositor) {
|
|
31
|
+
this._currentScene = scene;
|
|
32
|
+
const ctx = {
|
|
33
|
+
scene,
|
|
34
|
+
camera,
|
|
35
|
+
compositor
|
|
36
|
+
};
|
|
37
|
+
scene.frameUpdate();
|
|
38
|
+
if (camera && !Application.instance.device.isContextLost()) {
|
|
39
|
+
this._renderScene(ctx);
|
|
40
|
+
}
|
|
41
|
+
this._currentScene = null;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Disposes the render scheme
|
|
45
|
+
*/ dispose() {
|
|
46
|
+
this._dispose();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Gets the texture format for shadow maps
|
|
50
|
+
* @returns Texture format for shadow maps
|
|
51
|
+
*/ getShadowMapFormat() {
|
|
52
|
+
if (!this._shadowMapFormat) {
|
|
53
|
+
const device = Application.instance.device;
|
|
54
|
+
this._shadowMapFormat = device.getDeviceCaps().textureCaps.supportHalfFloatColorBuffer ? device.type === 'webgl' ? 'rgba16f' : 'r16f' : device.getDeviceCaps().textureCaps.supportFloatColorBuffer ? device.type === 'webgl' ? 'rgba32f' : 'r32f' : 'rgba8unorm';
|
|
55
|
+
}
|
|
56
|
+
return this._shadowMapFormat;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { RenderScheme };
|
|
61
|
+
//# sourceMappingURL=renderscheme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderscheme.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|