@zephyr3d/scene 0.3.1 → 0.5.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.
Files changed (174) hide show
  1. package/dist/animation/animation.js +25 -117
  2. package/dist/animation/animation.js.map +1 -1
  3. package/dist/animation/animationset.js +164 -24
  4. package/dist/animation/animationset.js.map +1 -1
  5. package/dist/animation/animationtrack.js +6 -18
  6. package/dist/animation/animationtrack.js.map +1 -1
  7. package/dist/animation/eulerrotationtrack.js +16 -6
  8. package/dist/animation/eulerrotationtrack.js.map +1 -1
  9. package/dist/animation/morphtarget.js +104 -0
  10. package/dist/animation/morphtarget.js.map +1 -0
  11. package/dist/animation/morphtrack.js +68 -0
  12. package/dist/animation/morphtrack.js.map +1 -0
  13. package/dist/animation/rotationtrack.js +15 -7
  14. package/dist/animation/rotationtrack.js.map +1 -1
  15. package/dist/animation/scaletrack.js +15 -7
  16. package/dist/animation/scaletrack.js.map +1 -1
  17. package/dist/animation/skeleton.js +101 -1
  18. package/dist/animation/skeleton.js.map +1 -1
  19. package/dist/animation/translationtrack.js +15 -7
  20. package/dist/animation/translationtrack.js.map +1 -1
  21. package/dist/animation/usertrack.js +2 -2
  22. package/dist/app.js +4 -26
  23. package/dist/app.js.map +1 -1
  24. package/dist/asset/assetmanager.js +58 -107
  25. package/dist/asset/assetmanager.js.map +1 -1
  26. package/dist/asset/loaders/dds/dds.js +77 -3
  27. package/dist/asset/loaders/dds/dds.js.map +1 -1
  28. package/dist/asset/loaders/dds/dds_loader.js +1 -1
  29. package/dist/asset/loaders/gltf/gltf_loader.js +284 -45
  30. package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -1
  31. package/dist/asset/loaders/image/tga_Loader.js +1 -1
  32. package/dist/asset/model.js +13 -0
  33. package/dist/asset/model.js.map +1 -1
  34. package/dist/blitter/blitter.js +2 -2
  35. package/dist/camera/camera.js +83 -5
  36. package/dist/camera/camera.js.map +1 -1
  37. package/dist/index.d.ts +5212 -4785
  38. package/dist/index.js +6 -7
  39. package/dist/index.js.map +1 -1
  40. package/dist/material/blinn.js +9 -4
  41. package/dist/material/blinn.js.map +1 -1
  42. package/dist/material/grassmat.js +127 -0
  43. package/dist/material/grassmat.js.map +1 -0
  44. package/dist/material/grassmaterial.js +15 -0
  45. package/dist/material/grassmaterial.js.map +1 -1
  46. package/dist/material/lambert.js +22 -17
  47. package/dist/material/lambert.js.map +1 -1
  48. package/dist/material/lightmodel.js +7 -6
  49. package/dist/material/lightmodel.js.map +1 -1
  50. package/dist/material/lit.js +99 -5
  51. package/dist/material/lit.js.map +1 -1
  52. package/dist/material/material.js +88 -347
  53. package/dist/material/material.js.map +1 -1
  54. package/dist/material/meshmaterial.js +122 -102
  55. package/dist/material/meshmaterial.js.map +1 -1
  56. package/dist/material/mixins/albedocolor.js +11 -3
  57. package/dist/material/mixins/albedocolor.js.map +1 -1
  58. package/dist/material/mixins/lightmodel/blinnphong.js +1 -1
  59. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +3 -3
  60. package/dist/material/mixins/lightmodel/pbrspecularglossness.js +3 -3
  61. package/dist/material/mixins/lit.js +2 -2
  62. package/dist/material/mixins/pbr/common.js +433 -10
  63. package/dist/material/mixins/pbr/common.js.map +1 -1
  64. package/dist/material/pbrmr.js +17 -6
  65. package/dist/material/pbrmr.js.map +1 -1
  66. package/dist/material/pbrsg.js +16 -9
  67. package/dist/material/pbrsg.js.map +1 -1
  68. package/dist/material/shader/helper.js +186 -117
  69. package/dist/material/shader/helper.js.map +1 -1
  70. package/dist/material/terrainlightmodel.js +3 -1
  71. package/dist/material/terrainlightmodel.js.map +1 -1
  72. package/dist/material/terrainmat.js +357 -0
  73. package/dist/material/terrainmat.js.map +1 -0
  74. package/dist/material/terrainmaterial.js +16 -0
  75. package/dist/material/terrainmaterial.js.map +1 -1
  76. package/dist/material/unlit.js +8 -4
  77. package/dist/material/unlit.js.map +1 -1
  78. package/dist/posteffect/bloom.js +34 -45
  79. package/dist/posteffect/bloom.js.map +1 -1
  80. package/dist/posteffect/compositor.js +11 -41
  81. package/dist/posteffect/compositor.js.map +1 -1
  82. package/dist/posteffect/fxaa.js +1 -2
  83. package/dist/posteffect/fxaa.js.map +1 -1
  84. package/dist/posteffect/grayscale.js +1 -2
  85. package/dist/posteffect/grayscale.js.map +1 -1
  86. package/dist/posteffect/posteffect.js +0 -74
  87. package/dist/posteffect/posteffect.js.map +1 -1
  88. package/dist/posteffect/sao.js +13 -29
  89. package/dist/posteffect/sao.js.map +1 -1
  90. package/dist/posteffect/tonemap.js +1 -2
  91. package/dist/posteffect/tonemap.js.map +1 -1
  92. package/dist/posteffect/water.js +20 -18
  93. package/dist/posteffect/water.js.map +1 -1
  94. package/dist/render/abuffer_oit.js +352 -0
  95. package/dist/render/abuffer_oit.js.map +1 -0
  96. package/dist/render/cull_visitor.js +3 -3
  97. package/dist/render/depth_pass.js +3 -2
  98. package/dist/render/depth_pass.js.map +1 -1
  99. package/dist/render/depthpass.js +16 -19
  100. package/dist/render/depthpass.js.map +1 -1
  101. package/dist/render/drawable_mixin.js +152 -0
  102. package/dist/render/drawable_mixin.js.map +1 -0
  103. package/dist/render/envlight.js +165 -31
  104. package/dist/render/envlight.js.map +1 -1
  105. package/dist/render/forward.js +3 -6
  106. package/dist/render/forward.js.map +1 -1
  107. package/dist/render/forward_pass.js +6 -5
  108. package/dist/render/forward_pass.js.map +1 -1
  109. package/dist/render/globalbindgroup_allocator.js +58 -0
  110. package/dist/render/globalbindgroup_allocator.js.map +1 -0
  111. package/dist/render/lightpass.js +83 -49
  112. package/dist/render/lightpass.js.map +1 -1
  113. package/dist/render/objectcolorpass.js +50 -0
  114. package/dist/render/objectcolorpass.js.map +1 -0
  115. package/dist/render/objectpool.js +295 -0
  116. package/dist/render/objectpool.js.map +1 -0
  117. package/dist/render/oit.js +16 -0
  118. package/dist/render/oit.js.map +1 -0
  119. package/dist/render/render_queue.js +294 -107
  120. package/dist/render/render_queue.js.map +1 -1
  121. package/dist/render/renderbundle_wrapper.js +20 -0
  122. package/dist/render/renderbundle_wrapper.js.map +1 -0
  123. package/dist/render/renderer.js +108 -28
  124. package/dist/render/renderer.js.map +1 -1
  125. package/dist/render/renderpass.js +96 -34
  126. package/dist/render/renderpass.js.map +1 -1
  127. package/dist/render/shadowmap_pass.js +18 -37
  128. package/dist/render/shadowmap_pass.js.map +1 -1
  129. package/dist/render/sky.js +2 -2
  130. package/dist/render/watermesh.js +140 -48
  131. package/dist/render/watermesh.js.map +1 -1
  132. package/dist/render/weightedblended_oit.js +171 -0
  133. package/dist/render/weightedblended_oit.js.map +1 -0
  134. package/dist/scene/batchgroup.js +8 -35
  135. package/dist/scene/batchgroup.js.map +1 -1
  136. package/dist/scene/environment.js +24 -4
  137. package/dist/scene/environment.js.map +1 -1
  138. package/dist/scene/graph_node.js +1 -10
  139. package/dist/scene/graph_node.js.map +1 -1
  140. package/dist/scene/mesh.js +42 -32
  141. package/dist/scene/mesh.js.map +1 -1
  142. package/dist/scene/scene.js +7 -37
  143. package/dist/scene/scene.js.map +1 -1
  144. package/dist/scene/scene_node.js +6 -2
  145. package/dist/scene/scene_node.js.map +1 -1
  146. package/dist/scene/terrain/grass.js +26 -11
  147. package/dist/scene/terrain/grass.js.map +1 -1
  148. package/dist/scene/terrain/patch.js +27 -15
  149. package/dist/scene/terrain/patch.js.map +1 -1
  150. package/dist/scene/terrain/quadtree.js +3 -3
  151. package/dist/scene/terrain/terrain.js +0 -8
  152. package/dist/scene/terrain/terrain.js.map +1 -1
  153. package/dist/shaders/lighting.js +14 -10
  154. package/dist/shaders/lighting.js.map +1 -1
  155. package/dist/shaders/water.js +4 -4
  156. package/dist/shadow/esm.js +4 -23
  157. package/dist/shadow/esm.js.map +1 -1
  158. package/dist/shadow/shadowmapper.js +45 -21
  159. package/dist/shadow/shadowmapper.js.map +1 -1
  160. package/dist/shadow/vsm.js +4 -25
  161. package/dist/shadow/vsm.js.map +1 -1
  162. package/dist/utility/draco/decoder.js +116 -0
  163. package/dist/utility/draco/decoder.js.map +1 -0
  164. package/dist/utility/sheenlut.js +196 -0
  165. package/dist/utility/sheenlut.js.map +1 -0
  166. package/dist/values.js +18 -1
  167. package/dist/values.js.map +1 -1
  168. package/package.json +7 -6
  169. package/dist/utility/noisetexture.js +0 -66
  170. package/dist/utility/noisetexture.js.map +0 -1
  171. package/dist/utility/textures/gradientnoise.js +0 -66
  172. package/dist/utility/textures/gradientnoise.js.map +0 -1
  173. package/dist/utility/textures/randomnoise.js +0 -41
  174. package/dist/utility/textures/randomnoise.js.map +0 -1
@@ -1,84 +1,98 @@
1
1
  import { Application } from '../app.js';
2
+ import { Vector3 } from '@zephyr3d/base';
2
3
  import { QUEUE_TRANSPARENT } from '../values.js';
3
4
  import { ProgramBuilder } from '@zephyr3d/device';
4
5
  import { ShaderHelper } from '../material/shader/helper.js';
5
6
  import '../material/lambert.js';
6
7
  import '../material/blinn.js';
7
8
  import '../material/unlit.js';
8
- import '../material/material.js';
9
9
  import '../material/meshmaterial.js';
10
10
  import '../material/grassmaterial.js';
11
11
  import '../material/terrainmaterial.js';
12
12
  import '../material/pbrmr.js';
13
13
  import '../material/pbrsg.js';
14
- import '@zephyr3d/base';
14
+ import { RenderBundleWrapper } from './renderbundle_wrapper.js';
15
15
 
16
+ const maxBufferSizeInFloats = 65536 / 4;
16
17
  /** @internal */ class InstanceBindGroupAllocator {
17
18
  static _instanceBindGroupLayout = null;
18
- _usedBindGroupList = [];
19
- _freeBindGroupList = [];
19
+ _bindGroupList = [];
20
20
  _allocFrameStamp;
21
21
  constructor(){
22
22
  this._allocFrameStamp = -1;
23
- this._usedBindGroupList = [];
24
- this._freeBindGroupList = [];
23
+ this._bindGroupList = [];
25
24
  }
26
- allocateInstanceBindGroup(framestamp) {
25
+ allocateInstanceBindGroup(framestamp, sizeInFloats) {
27
26
  // Reset if render frame changed
28
27
  if (this._allocFrameStamp !== framestamp) {
29
28
  this._allocFrameStamp = framestamp;
30
- this._freeBindGroupList.push(...this._usedBindGroupList);
31
- this._usedBindGroupList.length = 0;
29
+ for (const k of this._bindGroupList){
30
+ k.offset = 0;
31
+ }
32
32
  }
33
- let bindGroup = this._freeBindGroupList.pop();
34
- if (!bindGroup) {
35
- if (!InstanceBindGroupAllocator._instanceBindGroupLayout) {
36
- const buildInfo = new ProgramBuilder(Application.instance.device).buildRender({
37
- vertex (pb) {
38
- this[ShaderHelper.getWorldMatricesUniformName()] = pb.vec4[65536 >> 4]().uniformBuffer(3);
39
- pb.main(function() {});
40
- },
41
- fragment (pb) {
42
- this[ShaderHelper.getWorldMatricesUniformName()] = pb.vec4[65536 >> 4]().uniformBuffer(3);
43
- pb.main(function() {});
44
- }
45
- });
46
- InstanceBindGroupAllocator._instanceBindGroupLayout = buildInfo[2][3];
33
+ for (const k of this._bindGroupList){
34
+ if (k.offset + sizeInFloats <= maxBufferSizeInFloats) {
35
+ k.dirty = true;
36
+ return k;
47
37
  }
48
- bindGroup = {
49
- bindGroup: Application.instance.device.createBindGroup(InstanceBindGroupAllocator._instanceBindGroupLayout),
50
- buffer: new Float32Array(65536 >> 2),
51
- dirty: true
52
- };
53
- } else {
54
- bindGroup.dirty = true;
55
38
  }
56
- this._usedBindGroupList.push(bindGroup);
39
+ if (!InstanceBindGroupAllocator._instanceBindGroupLayout) {
40
+ const buildInfo = new ProgramBuilder(Application.instance.device).buildRender({
41
+ vertex (pb) {
42
+ this[ShaderHelper.getInstanceDataUniformName()] = pb.vec4[65536 >> 4]().uniformBuffer(3);
43
+ pb.main(function() {});
44
+ },
45
+ fragment (pb) {
46
+ pb.main(function() {});
47
+ }
48
+ });
49
+ InstanceBindGroupAllocator._instanceBindGroupLayout = buildInfo[2][3];
50
+ }
51
+ const bindGroup = {
52
+ bindGroup: Application.instance.device.createBindGroup(InstanceBindGroupAllocator._instanceBindGroupLayout),
53
+ buffer: new Float32Array(maxBufferSizeInFloats),
54
+ offset: 0,
55
+ dirty: true
56
+ };
57
+ this._bindGroupList.push(bindGroup);
57
58
  return bindGroup;
58
59
  }
59
60
  }
60
- const maxUniformSize = 65536 >> 2;
61
61
  const defaultInstanceBindGroupAlloator = new InstanceBindGroupAllocator();
62
62
  /**
63
63
  * A queue that contains the items to be rendered
64
64
  * @public
65
65
  */ class RenderQueue {
66
- /** @internal */ _itemLists;
66
+ /** @internal */ _itemList;
67
67
  /** @internal */ _renderPass;
68
68
  /** @internal */ _shadowedLightList;
69
69
  /** @internal */ _unshadowedLightList;
70
70
  /** @internal */ _sunLight;
71
71
  /** @internal */ _bindGroupAllocator;
72
+ /** @internal */ _ref;
73
+ /** @internal */ _instanceInfo;
74
+ /** @internal */ _needSceneColor;
75
+ /** @internal */ _drawTransparent;
76
+ /** @internal */ _objectColorMaps;
72
77
  /**
73
78
  * Creates an instance of a render queue
74
79
  * @param renderPass - The render pass to which the render queue belongs
75
80
  */ constructor(renderPass, bindGroupAllocator){
76
81
  this._bindGroupAllocator = bindGroupAllocator ?? defaultInstanceBindGroupAlloator;
77
- this._itemLists = {};
82
+ this._itemList = null;
78
83
  this._renderPass = renderPass;
79
84
  this._shadowedLightList = [];
80
85
  this._unshadowedLightList = [];
81
86
  this._sunLight = null;
87
+ this._ref = {
88
+ ref: this
89
+ };
90
+ this._instanceInfo = new Map();
91
+ this._needSceneColor = false;
92
+ this._drawTransparent = false;
93
+ this._objectColorMaps = [
94
+ new Map()
95
+ ];
82
96
  }
83
97
  /** The sun light */ get sunLight() {
84
98
  return this._sunLight;
@@ -86,13 +100,19 @@ const defaultInstanceBindGroupAlloator = new InstanceBindGroupAllocator();
86
100
  set sunLight(light) {
87
101
  this._sunLight = light;
88
102
  }
103
+ /** Whether this render queue requires scene color pass */ get needSceneColor() {
104
+ return this._needSceneColor;
105
+ }
106
+ /** Whether this render queue has transparent objects to be drawn */ get drawTransparent() {
107
+ return this._drawTransparent;
108
+ }
89
109
  /** The render pass to which the render queue belongs */ get renderPass() {
90
110
  return this._renderPass;
91
111
  }
92
112
  /**
93
113
  * Gets the items of the render queue
94
- */ get items() {
95
- return this._itemLists;
114
+ */ get itemList() {
115
+ return this._itemList;
96
116
  }
97
117
  /**
98
118
  * Gets the shadowed lights
@@ -105,6 +125,18 @@ const defaultInstanceBindGroupAlloator = new InstanceBindGroupAllocator();
105
125
  return this._unshadowedLightList;
106
126
  }
107
127
  /**
128
+ * Gets the indirect reference of this
129
+ */ get ref() {
130
+ return this._ref;
131
+ }
132
+ /**
133
+ * Gets the instance information for given drawable object
134
+ * @param drawable - The drawable object
135
+ * @returns The instane information for given drawable object, null if no exists
136
+ */ getInstanceInfo(drawable) {
137
+ return this._instanceInfo.get(drawable);
138
+ }
139
+ /**
108
140
  * Gets the maximum batch size of a given device
109
141
  * @returns The maximum batch size of the device
110
142
  *
@@ -129,108 +161,263 @@ const defaultInstanceBindGroupAlloator = new InstanceBindGroupAllocator();
129
161
  * Push items from another render queue
130
162
  * @param queue - The render queue to be pushed
131
163
  */ pushRenderQueue(queue) {
132
- if (queue && queue !== this) {
133
- for(const k in queue._itemLists){
134
- const l = queue._itemLists[k];
135
- if (l) {
136
- let list = this._itemLists[k];
137
- if (!list) {
138
- list = {
139
- opaqueList: [],
140
- opaqueInstanceList: {},
141
- transList: [],
142
- transInstanceList: {}
143
- };
144
- this._itemLists[k] = list;
145
- }
146
- list.opaqueList.push(...l.opaqueList);
147
- list.transList.push(...l.transList);
148
- }
149
- }
164
+ const newItemLists = queue._itemList;
165
+ if (!newItemLists) {
166
+ return;
150
167
  }
168
+ if (!this._itemList) {
169
+ this._itemList = this.newRenderItemList();
170
+ }
171
+ this._itemList.opaque.lit.push(...newItemLists.opaque.lit);
172
+ this._itemList.opaque.unlit.push(...newItemLists.opaque.unlit);
173
+ this._itemList.transmission.lit.push(...newItemLists.transmission.lit);
174
+ this._itemList.transmission.unlit.push(...newItemLists.transmission.unlit);
175
+ this._itemList.transparent.lit.push(...newItemLists.transparent.lit);
176
+ this._itemList.transparent.unlit.push(...newItemLists.transparent.unlit);
177
+ this._needSceneColor ||= queue._needSceneColor;
178
+ this._drawTransparent ||= queue._drawTransparent;
179
+ this._objectColorMaps.push(...queue._objectColorMaps);
151
180
  }
152
181
  /**
153
182
  * Push an item to the render queue
154
183
  * @param camera - The camera for drawing the item
155
184
  * @param drawable - The object to be drawn
156
- * @param renderOrder - Render order of the object
157
- */ push(camera, drawable, renderOrder) {
185
+ */ push(camera, drawable) {
158
186
  if (drawable) {
159
- let itemList = this._itemLists[renderOrder];
160
- if (!itemList) {
161
- itemList = {
162
- opaqueList: [],
163
- opaqueInstanceList: {},
164
- transList: [],
165
- transInstanceList: {}
166
- };
167
- this._itemLists[renderOrder] = itemList;
187
+ if (!this._itemList) {
188
+ this._itemList = this.newRenderItemList();
168
189
  }
169
190
  const trans = drawable.getQueueType() === QUEUE_TRANSPARENT;
170
- const list = trans ? itemList.transList : itemList.opaqueList;
191
+ const unlit = drawable.isUnlit();
192
+ const transmission = !trans && drawable.needSceneColor();
193
+ this._needSceneColor ||= transmission;
194
+ this._drawTransparent ||= trans;
195
+ if (camera.enablePicking) {
196
+ drawable.getMaterial().objectColor = drawable.getObjectColor();
197
+ this._objectColorMaps[0].set(drawable.getId(), drawable);
198
+ }
171
199
  if (drawable.isBatchable()) {
172
- const instanceList = trans ? itemList.transInstanceList : itemList.opaqueInstanceList;
200
+ const instanceList = trans ? unlit ? this._itemList.transparent.unlit[0].instanceList : this._itemList.transparent.lit[0].instanceList : unlit ? transmission ? this._itemList.transmission.unlit[0].instanceList : this._itemList.opaque.unlit[0].instanceList : transmission ? this._itemList.transmission.lit[0].instanceList : this._itemList.opaque.lit[0].instanceList;
173
201
  const hash = drawable.getInstanceId(this._renderPass);
174
- const index = instanceList[hash];
175
- if (index === undefined || list[index].instanceData.currentSize + list[index].instanceData.stride > list[index].instanceData.maxSize) {
176
- instanceList[hash] = list.length;
177
- const bindGroup = this._bindGroupAllocator.allocateInstanceBindGroup(Application.instance.device.frameInfo.frameCounter);
178
- drawable.setInstanceDataBuffer(this._renderPass, bindGroup, 0);
179
- bindGroup.buffer.set(drawable.getXForm().worldMatrix);
180
- let currentSize = 4;
181
- const instanceUniforms = drawable.getInstanceUniforms();
182
- if (instanceUniforms) {
183
- bindGroup.buffer.set(instanceUniforms, currentSize * 4);
184
- currentSize += instanceUniforms.length >> 2;
185
- }
186
- const maxSize = Math.floor(maxUniformSize / currentSize);
187
- list.push({
188
- drawable,
189
- sortDistance: drawable.getSortDistance(camera),
190
- instanceData: {
191
- bindGroup,
192
- currentSize,
193
- maxSize,
194
- stride: currentSize,
195
- hash: hash
196
- }
197
- });
198
- } else {
199
- const instanceData = list[index].instanceData;
200
- drawable.setInstanceDataBuffer(this._renderPass, instanceData.bindGroup, instanceData.currentSize * 4);
201
- instanceData.bindGroup.buffer.set(drawable.getXForm().worldMatrix, instanceData.currentSize * 4);
202
- instanceData.currentSize += 4;
203
- const instanceUniforms = drawable.getInstanceUniforms();
204
- if (instanceUniforms) {
205
- instanceData.bindGroup.buffer.set(instanceUniforms, instanceData.currentSize * 4);
206
- instanceData.currentSize += instanceUniforms.length >> 2;
207
- }
202
+ let drawableList = instanceList[hash];
203
+ if (!drawableList) {
204
+ drawableList = [];
205
+ instanceList[hash] = drawableList;
208
206
  }
207
+ drawableList.push(drawable);
209
208
  } else {
210
- list.push({
209
+ const list = trans ? unlit ? this._itemList.transparent.unlit[0] : this._itemList.transparent.lit[0] : unlit ? transmission ? this._itemList.transmission.unlit[0] : this._itemList.opaque.unlit[0] : transmission ? this._itemList.transmission.lit[0] : this._itemList.opaque.lit[0];
210
+ const skinAnimation = !!drawable.getBoneMatrices();
211
+ const morphAnimation = !!drawable.getMorphData();
212
+ let queue;
213
+ if (skinAnimation && morphAnimation) {
214
+ queue = list.skinAndMorphItemList;
215
+ } else if (skinAnimation) {
216
+ queue = list.skinItemList;
217
+ } else if (morphAnimation) {
218
+ queue = list.morphItemList;
219
+ } else {
220
+ queue = list.itemList;
221
+ }
222
+ this.binaryInsert(queue, {
211
223
  drawable,
212
224
  sortDistance: drawable.getSortDistance(camera),
213
225
  instanceData: null
214
226
  });
227
+ drawable.applyTransformUniforms(this);
228
+ const mat = drawable.getMaterial();
229
+ if (mat) {
230
+ list.materialList.add(mat.coreMaterial);
231
+ }
215
232
  }
233
+ drawable.pushRenderQueueRef(this._ref);
216
234
  }
217
235
  }
236
+ /** @internal */ getDrawableByColor(c) {
237
+ const id = (c[0] << 24) + (c[1] << 16) + (c[2] << 8) + c[3];
238
+ for (const m of this._objectColorMaps){
239
+ const drawable = m.get(id);
240
+ if (drawable) {
241
+ return drawable;
242
+ }
243
+ }
244
+ return null;
245
+ }
218
246
  /**
219
247
  * Removes all items in the render queue
220
248
  */ reset() {
221
- this._itemLists = {};
249
+ this._itemList = null;
222
250
  this._shadowedLightList = [];
223
251
  this._unshadowedLightList = [];
224
252
  this._sunLight = null;
253
+ this._needSceneColor = false;
254
+ this._drawTransparent = false;
255
+ }
256
+ /** @internal */ dispose() {
257
+ this._ref.ref = null;
258
+ this._ref = null;
259
+ this.reset();
260
+ }
261
+ /** @internal */ end(camera, createRenderBundles) {
262
+ const frameCounter = Application.instance.device.frameInfo.frameCounter;
263
+ const itemList = this._itemList;
264
+ if (!this.itemList) {
265
+ return this;
266
+ }
267
+ const lists = [
268
+ itemList.opaque.lit,
269
+ itemList.opaque.unlit,
270
+ itemList.transmission.lit,
271
+ itemList.transmission.unlit,
272
+ itemList.transparent.lit,
273
+ itemList.transparent.unlit
274
+ ];
275
+ for(let i = 0; i < lists.length; i++){
276
+ const list = lists[i];
277
+ for (const info of list){
278
+ if (info.renderQueue !== this) {
279
+ continue;
280
+ }
281
+ const instanceList = info.instanceList;
282
+ for(const x in instanceList){
283
+ const drawables = instanceList[x];
284
+ if (drawables.length === 1) {
285
+ this.binaryInsert(info.itemList, {
286
+ drawable: drawables[0],
287
+ sortDistance: drawables[0].getSortDistance(camera),
288
+ instanceData: null
289
+ });
290
+ drawables[0].applyTransformUniforms(this);
291
+ const mat = drawables[0].getMaterial();
292
+ if (mat) {
293
+ info.materialList.add(mat.coreMaterial);
294
+ }
295
+ } else {
296
+ let bindGroup = null;
297
+ let item = null;
298
+ for(let i = 0; i < drawables.length; i++){
299
+ const drawable = drawables[i];
300
+ const instanceUniforms = drawable.getInstanceUniforms();
301
+ const instanceUniformsSize = instanceUniforms?.length ?? 0;
302
+ const stride = 16 + instanceUniformsSize;
303
+ if (!bindGroup || bindGroup.offset + stride > maxBufferSizeInFloats) {
304
+ bindGroup = this._bindGroupAllocator.allocateInstanceBindGroup(frameCounter, stride);
305
+ item = {
306
+ drawable,
307
+ sortDistance: drawable.getSortDistance(camera),
308
+ instanceData: {
309
+ bindGroup,
310
+ offset: bindGroup.offset,
311
+ numInstances: 0,
312
+ stride
313
+ }
314
+ };
315
+ this.binaryInsert(info.instanceItemList, item);
316
+ drawable.applyInstanceOffsetAndStride(this, stride, bindGroup.offset);
317
+ }
318
+ const instanceInfo = {
319
+ bindGroup,
320
+ offset: bindGroup.offset
321
+ };
322
+ this._instanceInfo.set(drawable, instanceInfo);
323
+ drawable.applyTransformUniforms(this);
324
+ drawable.applyMaterialUniforms(instanceInfo);
325
+ bindGroup.offset += stride;
326
+ item.instanceData.numInstances++;
327
+ const mat = drawable.getMaterial();
328
+ if (mat) {
329
+ info.materialList.add(mat.coreMaterial);
330
+ }
331
+ }
332
+ }
333
+ }
334
+ info.instanceList = {};
335
+ if (createRenderBundles) {
336
+ if (info.itemList.length > 0) {
337
+ info.renderBundle = new RenderBundleWrapper();
338
+ }
339
+ if (info.skinItemList.length > 0) {
340
+ info.skinRenderBundle = new RenderBundleWrapper();
341
+ }
342
+ if (info.morphItemList.length > 0) {
343
+ info.morphRenderBundle = new RenderBundleWrapper();
344
+ }
345
+ if (info.skinAndMorphItemList.length > 0) {
346
+ info.skinAndMorphRenderBundle = new RenderBundleWrapper();
347
+ }
348
+ if (info.instanceItemList.length > 0) {
349
+ info.instanceRenderBundle = new RenderBundleWrapper();
350
+ }
351
+ }
352
+ }
353
+ }
354
+ return this;
355
+ }
356
+ binaryInsert(itemList, item) {
357
+ let left = 0;
358
+ let right = itemList.length - 1;
359
+ const newInstanceId = item.drawable.getMaterial().instanceId;
360
+ while(left <= right){
361
+ const mid = Math.floor((left + right) / 2);
362
+ const instanceId = itemList[mid].drawable.getMaterial().instanceId;
363
+ if (instanceId === newInstanceId) {
364
+ itemList.splice(mid + 1, 0, item);
365
+ return;
366
+ } else if (instanceId < newInstanceId) {
367
+ left = mid + 1;
368
+ } else {
369
+ right = mid - 1;
370
+ }
371
+ }
372
+ itemList.splice(left, 0, item);
225
373
  }
226
374
  /**
227
375
  * Sorts the items in the render queue for rendering
228
- */ sortItems() {
229
- for (const list of Object.values(this._itemLists)){
230
- list.opaqueList.sort((a, b)=>a.sortDistance - b.sortDistance);
231
- list.transList.sort((a, b)=>b.sortDistance - a.sortDistance);
376
+ */ sortTransparentItems(cameraPos) {
377
+ if (this._itemList) {
378
+ this._itemList.transparent.lit[0].itemList.sort((a, b)=>this.drawableDistanceToCamera(b.drawable, cameraPos) - this.drawableDistanceToCamera(a.drawable, cameraPos));
379
+ this._itemList.transparent.lit[0].skinItemList.sort((a, b)=>this.drawableDistanceToCamera(b.drawable, cameraPos) - this.drawableDistanceToCamera(a.drawable, cameraPos));
380
+ this._itemList.transparent.lit[0].morphItemList.sort((a, b)=>this.drawableDistanceToCamera(b.drawable, cameraPos) - this.drawableDistanceToCamera(a.drawable, cameraPos));
381
+ this._itemList.transparent.lit[0].skinAndMorphItemList.sort((a, b)=>this.drawableDistanceToCamera(b.drawable, cameraPos) - this.drawableDistanceToCamera(a.drawable, cameraPos));
382
+ this._itemList.transparent.unlit[0].itemList.sort((a, b)=>this.drawableDistanceToCamera(b.drawable, cameraPos) - this.drawableDistanceToCamera(a.drawable, cameraPos));
383
+ this._itemList.transparent.unlit[0].skinItemList.sort((a, b)=>this.drawableDistanceToCamera(b.drawable, cameraPos) - this.drawableDistanceToCamera(a.drawable, cameraPos));
384
+ this._itemList.transparent.unlit[0].morphItemList.sort((a, b)=>this.drawableDistanceToCamera(b.drawable, cameraPos) - this.drawableDistanceToCamera(a.drawable, cameraPos));
385
+ this._itemList.transparent.unlit[0].skinAndMorphItemList.sort((a, b)=>this.drawableDistanceToCamera(b.drawable, cameraPos) - this.drawableDistanceToCamera(a.drawable, cameraPos));
232
386
  }
233
387
  }
388
+ drawableDistanceToCamera(drawable, cameraPos) {
389
+ const drawablePos = drawable.getXForm().position;
390
+ return Vector3.distanceSq(drawablePos, cameraPos);
391
+ }
392
+ newRenderItemListInfo() {
393
+ return {
394
+ itemList: [],
395
+ skinItemList: [],
396
+ morphItemList: [],
397
+ skinAndMorphItemList: [],
398
+ instanceItemList: [],
399
+ materialList: new Set(),
400
+ instanceList: {},
401
+ renderQueue: this
402
+ };
403
+ }
404
+ newRenderItemListBundle() {
405
+ return {
406
+ lit: [
407
+ this.newRenderItemListInfo()
408
+ ],
409
+ unlit: [
410
+ this.newRenderItemListInfo()
411
+ ]
412
+ };
413
+ }
414
+ newRenderItemList() {
415
+ return {
416
+ opaque: this.newRenderItemListBundle(),
417
+ transmission: this.newRenderItemListBundle(),
418
+ transparent: this.newRenderItemListBundle()
419
+ };
420
+ }
234
421
  }
235
422
 
236
423
  export { InstanceBindGroupAllocator, RenderQueue };
@@ -1 +1 @@
1
- {"version":3,"file":"render_queue.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"render_queue.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,20 @@
1
+ import { Application } from '../app.js';
2
+
3
+ class RenderBundleWrapper {
4
+ _renderBundles;
5
+ constructor(){
6
+ this._renderBundles = {};
7
+ }
8
+ getRenderBundle(hash) {
9
+ return this._renderBundles[hash] ?? null;
10
+ }
11
+ beginRenderBundle() {
12
+ Application.instance.device.beginCapture();
13
+ }
14
+ endRenderBundle(hash) {
15
+ this._renderBundles[hash] = Application.instance.device.endCapture();
16
+ }
17
+ }
18
+
19
+ export { RenderBundleWrapper };
20
+ //# sourceMappingURL=renderbundle_wrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderbundle_wrapper.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;"}