@zephyr3d/scene 0.3.0 → 0.4.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 (100) hide show
  1. package/dist/asset/assetmanager.js +1 -1
  2. package/dist/asset/loaders/gltf/gltf_loader.js +4 -8
  3. package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -1
  4. package/dist/camera/camera.js +25 -2
  5. package/dist/camera/camera.js.map +1 -1
  6. package/dist/index.d.ts +4641 -4371
  7. package/dist/index.js +4 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/material/grassmaterial.js +15 -0
  10. package/dist/material/grassmaterial.js.map +1 -1
  11. package/dist/material/material.js +79 -347
  12. package/dist/material/material.js.map +1 -1
  13. package/dist/material/meshmaterial.js +88 -100
  14. package/dist/material/meshmaterial.js.map +1 -1
  15. package/dist/material/mixins/albedocolor.js +11 -3
  16. package/dist/material/mixins/albedocolor.js.map +1 -1
  17. package/dist/material/mixins/lightmodel/blinnphong.js +1 -1
  18. package/dist/material/mixins/lightmodel/pbrspecularglossness.js +8 -1
  19. package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
  20. package/dist/material/mixins/pbr/common.js +2 -0
  21. package/dist/material/mixins/pbr/common.js.map +1 -1
  22. package/dist/material/mixins/vertexcolor.js +2 -0
  23. package/dist/material/mixins/vertexcolor.js.map +1 -1
  24. package/dist/material/pbrmr.js +1 -1
  25. package/dist/material/pbrsg.js +9 -4
  26. package/dist/material/pbrsg.js.map +1 -1
  27. package/dist/material/shader/helper.js +94 -115
  28. package/dist/material/shader/helper.js.map +1 -1
  29. package/dist/material/terrainmaterial.js +16 -0
  30. package/dist/material/terrainmaterial.js.map +1 -1
  31. package/dist/posteffect/bloom.js +3 -4
  32. package/dist/posteffect/bloom.js.map +1 -1
  33. package/dist/posteffect/compositor.js +5 -6
  34. package/dist/posteffect/compositor.js.map +1 -1
  35. package/dist/posteffect/fxaa.js +1 -2
  36. package/dist/posteffect/fxaa.js.map +1 -1
  37. package/dist/posteffect/grayscale.js +1 -2
  38. package/dist/posteffect/grayscale.js.map +1 -1
  39. package/dist/posteffect/posteffect.js +0 -74
  40. package/dist/posteffect/posteffect.js.map +1 -1
  41. package/dist/posteffect/sao.js +2 -5
  42. package/dist/posteffect/sao.js.map +1 -1
  43. package/dist/posteffect/tonemap.js +1 -2
  44. package/dist/posteffect/tonemap.js.map +1 -1
  45. package/dist/posteffect/water.js +18 -14
  46. package/dist/posteffect/water.js.map +1 -1
  47. package/dist/render/abuffer_oit.js +352 -0
  48. package/dist/render/abuffer_oit.js.map +1 -0
  49. package/dist/render/depthpass.js +10 -13
  50. package/dist/render/depthpass.js.map +1 -1
  51. package/dist/render/drawable_mixin.js +110 -0
  52. package/dist/render/drawable_mixin.js.map +1 -0
  53. package/dist/render/globalbindgroup_allocator.js +58 -0
  54. package/dist/render/globalbindgroup_allocator.js.map +1 -0
  55. package/dist/render/lightpass.js +69 -43
  56. package/dist/render/lightpass.js.map +1 -1
  57. package/dist/render/oit.js +16 -0
  58. package/dist/render/oit.js.map +1 -0
  59. package/dist/render/render_queue.js +250 -96
  60. package/dist/render/render_queue.js.map +1 -1
  61. package/dist/render/renderbundle_wrapper.js +20 -0
  62. package/dist/render/renderbundle_wrapper.js.map +1 -0
  63. package/dist/render/renderer.js +12 -9
  64. package/dist/render/renderer.js.map +1 -1
  65. package/dist/render/renderpass.js +92 -34
  66. package/dist/render/renderpass.js.map +1 -1
  67. package/dist/render/shadowmap_pass.js +12 -31
  68. package/dist/render/shadowmap_pass.js.map +1 -1
  69. package/dist/render/sky.js +2 -2
  70. package/dist/render/watermesh.js +140 -48
  71. package/dist/render/watermesh.js.map +1 -1
  72. package/dist/render/weightedblended_oit.js +188 -0
  73. package/dist/render/weightedblended_oit.js.map +1 -0
  74. package/dist/scene/batchgroup.js +8 -35
  75. package/dist/scene/batchgroup.js.map +1 -1
  76. package/dist/scene/environment.js +2 -3
  77. package/dist/scene/environment.js.map +1 -1
  78. package/dist/scene/graph_node.js +1 -1
  79. package/dist/scene/mesh.js +11 -32
  80. package/dist/scene/mesh.js.map +1 -1
  81. package/dist/scene/octree.js +3 -3
  82. package/dist/scene/scene.js +2 -29
  83. package/dist/scene/scene.js.map +1 -1
  84. package/dist/scene/scene_node.js +6 -1
  85. package/dist/scene/scene_node.js.map +1 -1
  86. package/dist/scene/terrain/grass.js +17 -11
  87. package/dist/scene/terrain/grass.js.map +1 -1
  88. package/dist/scene/terrain/patch.js +18 -15
  89. package/dist/scene/terrain/patch.js.map +1 -1
  90. package/dist/scene/terrain/quadtree.js +1 -1
  91. package/dist/scene/terrain/terrain.js +0 -8
  92. package/dist/scene/terrain/terrain.js.map +1 -1
  93. package/dist/shaders/water.js +4 -4
  94. package/dist/shadow/esm.js +0 -1
  95. package/dist/shadow/esm.js.map +1 -1
  96. package/dist/shadow/shadowmapper.js +1 -2
  97. package/dist/shadow/shadowmapper.js.map +1 -1
  98. package/dist/shadow/vsm.js +1 -2
  99. package/dist/shadow/vsm.js.map +1 -1
  100. package/package.json +4 -4
@@ -0,0 +1,188 @@
1
+ import { OIT } from './oit.js';
2
+ import { drawFullscreenQuad } from './fullscreenquad.js';
3
+ import { Vector4 } from '@zephyr3d/base';
4
+
5
+ /**
6
+ * Weighted-blended OIT renderer.
7
+ *
8
+ * @remarks
9
+ * The weighed-blended OIT renderer supports both WebGL, WebGL2 and WebGPU device.
10
+ *
11
+ * @public
12
+ */ class WeightedBlendedOIT extends OIT {
13
+ /** Type name of WeightedBlendedOIT */ static type = 'wb';
14
+ static _compositeProgram;
15
+ static _compositeBindGroup;
16
+ static _compositeRenderStates;
17
+ _accumBuffer;
18
+ /**
19
+ * Creates an instance of WeightedBlendedOIT class.
20
+ */ constructor(){
21
+ super();
22
+ this._accumBuffer = null;
23
+ }
24
+ /**
25
+ * {@inheritDoc OIT.getType}
26
+ */ getType() {
27
+ return WeightedBlendedOIT.type;
28
+ }
29
+ /**
30
+ * {@inheritDoc OIT.supportDevice}
31
+ */ supportDevice(deviceType) {
32
+ return true;
33
+ }
34
+ /**
35
+ * {@inheritDoc OIT.dispose}
36
+ */ dispose() {
37
+ return;
38
+ }
39
+ /**
40
+ * {@inheritDoc OIT.begin}
41
+ */ begin(ctx) {
42
+ return 1;
43
+ }
44
+ /**
45
+ * {@inheritDoc OIT.end}
46
+ */ end(ctx) {
47
+ return;
48
+ }
49
+ /**
50
+ * {@inheritDoc OIT.setupFragmentOutput}
51
+ */ setupFragmentOutput(scope) {
52
+ const pb = scope.$builder;
53
+ scope.$outputs.outColor = pb.vec4();
54
+ scope.$outputs.outAlpha = pb.getDevice().type === 'webgl' ? pb.vec4() : pb.float();
55
+ }
56
+ /**
57
+ * {@inheritDoc OIT.beginPass}
58
+ */ beginPass(ctx, pass) {
59
+ const device = ctx.device;
60
+ const accumBuffer = this.getAccumFramebuffer(ctx, device);
61
+ device.pushDeviceStates();
62
+ device.setFramebuffer(accumBuffer);
63
+ device.clearFrameBuffer(new Vector4(0, 0, 0, 1), null, null);
64
+ return true;
65
+ }
66
+ /**
67
+ * {@inheritDoc OIT.endPass}
68
+ */ endPass(ctx, pass) {
69
+ const device = ctx.device;
70
+ const accumBuffer = device.getFramebuffer();
71
+ device.popDeviceStates();
72
+ const accumTargets = accumBuffer.getColorAttachments();
73
+ this.composite(ctx, device, accumTargets[0], accumTargets[1]);
74
+ }
75
+ /**
76
+ * {@inheritDoc OIT.calculateHash}
77
+ */ calculateHash() {
78
+ return this.getType();
79
+ }
80
+ /**
81
+ * {@inheritDoc OIT.applyUniforms}
82
+ */ applyUniforms(ctx, bindGroup) {
83
+ return;
84
+ }
85
+ /**
86
+ * {@inheritDoc OIT.outputFragmentColor}
87
+ */ outputFragmentColor(scope, color) {
88
+ const pb = scope.$builder;
89
+ pb.func('Z_WBOIT_depthWeight', [
90
+ pb.float('z'),
91
+ pb.float('a')
92
+ ], function() {
93
+ this.$return(pb.clamp(pb.mul(pb.pow(pb.add(pb.min(1, pb.mul(this.a, 10)), 0.01), 3), 1e8, pb.pow(pb.sub(1, pb.mul(this.z, 0.9)), 2)), 1e-2, 3e3));
94
+ });
95
+ pb.func('Z_WBOIT_output', [
96
+ pb.vec4('color')
97
+ ], function() {
98
+ this.$l.w = this.Z_WBOIT_depthWeight(this.$builtins.fragCoord.z, this.color.a);
99
+ this.$outputs[0] = pb.vec4(pb.mul(this.color.rgb, this.w), this.color.a);
100
+ this.$outputs[1] = pb.getDevice().type === 'webgl' ? pb.vec4(pb.mul(this.color.a, this.w)) : pb.mul(this.color.a, this.w);
101
+ });
102
+ scope.Z_WBOIT_output(color);
103
+ return true;
104
+ }
105
+ /**
106
+ * {@inheritDoc OIT.setRenderStates}
107
+ */ setRenderStates(rs) {
108
+ const blendingState = rs.useBlendingState();
109
+ blendingState.enable(true);
110
+ blendingState.setBlendEquation('add', 'add');
111
+ blendingState.setBlendFuncRGB('one', 'one');
112
+ blendingState.setBlendFuncAlpha('zero', 'inv-src-alpha');
113
+ const depthState = rs.useDepthState();
114
+ depthState.enableWrite(false).enableTest(true);
115
+ }
116
+ /** @internal */ composite(ctx, device, accumColor, accumAlpha) {
117
+ device.setProgram(WeightedBlendedOIT.getCompositeProgram(device));
118
+ WeightedBlendedOIT._compositeBindGroup.setTexture('accumColorTex', accumColor);
119
+ WeightedBlendedOIT._compositeBindGroup.setTexture('accumAlphaTex', accumAlpha);
120
+ device.setBindGroup(0, WeightedBlendedOIT._compositeBindGroup);
121
+ drawFullscreenQuad(WeightedBlendedOIT._compositeRenderStates);
122
+ }
123
+ /** @internal */ getAccumFramebuffer(ctx, device) {
124
+ const vp = device.getViewport();
125
+ const width = device.screenToDevice(vp.width);
126
+ const height = device.screenToDevice(vp.height);
127
+ if (this._accumBuffer) {
128
+ if (this._accumBuffer.getWidth() !== width || this._accumBuffer.getHeight() !== height || this._accumBuffer.getDepthAttachment() !== ctx.depthTexture) {
129
+ this._accumBuffer.dispose();
130
+ this._accumBuffer = null;
131
+ }
132
+ }
133
+ if (!this._accumBuffer) {
134
+ const accumColor = device.createTexture2D('rgba16f', width, height, {
135
+ samplerOptions: {
136
+ mipFilter: 'none'
137
+ }
138
+ });
139
+ const accumAlpha = device.createTexture2D(device.type === 'webgl' ? 'rgba16f' : 'r16f', width, height, {
140
+ samplerOptions: {
141
+ mipFilter: 'none'
142
+ }
143
+ });
144
+ this._accumBuffer = device.createFrameBuffer([
145
+ accumColor,
146
+ accumAlpha
147
+ ], ctx.depthTexture);
148
+ }
149
+ return this._accumBuffer;
150
+ }
151
+ /** @internal */ static getCompositeProgram(device) {
152
+ if (!this._compositeProgram) {
153
+ this._compositeProgram = device.buildRenderProgram({
154
+ vertex (pb) {
155
+ this.$inputs.pos = pb.vec2().attrib('position');
156
+ this.$outputs.uv = pb.vec2();
157
+ pb.main(function() {
158
+ this.$builtins.position = pb.vec4(this.$inputs.pos, 1, 1);
159
+ this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));
160
+ if (device.type === 'webgpu') {
161
+ this.$builtins.position.y = pb.neg(this.$builtins.position.y);
162
+ }
163
+ });
164
+ },
165
+ fragment (pb) {
166
+ this.$outputs.outColor = pb.vec4();
167
+ this.accumColorTex = pb.tex2D().uniform(0);
168
+ this.accumAlphaTex = pb.tex2D().uniform(0);
169
+ pb.main(function() {
170
+ this.$l.accumColor = pb.textureSample(this.accumColorTex, this.$inputs.uv);
171
+ this.$l.accumAlpha = pb.textureSample(this.accumAlphaTex, this.$inputs.uv);
172
+ this.$l.r = this.accumColor.a;
173
+ this.accumColor.a = this.accumAlpha.r;
174
+ this.$outputs.outColor = pb.vec4(pb.div(this.accumColor.rgb, pb.clamp(this.accumColor.a, 0.0001, 50000)), this.r);
175
+ });
176
+ }
177
+ });
178
+ this._compositeBindGroup = device.createBindGroup(this._compositeProgram.bindGroupLayouts[0]);
179
+ this._compositeRenderStates = device.createRenderStateSet();
180
+ this._compositeRenderStates.useBlendingState().enable(true).setBlendFuncRGB('inv-src-alpha', 'src-alpha').setBlendFuncAlpha('zero', 'one');
181
+ this._compositeRenderStates.useDepthState().enableTest(false).enableWrite(false);
182
+ }
183
+ return this._compositeProgram;
184
+ }
185
+ }
186
+
187
+ export { WeightedBlendedOIT };
188
+ //# sourceMappingURL=weightedblended_oit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"weightedblended_oit.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,23 +1,22 @@
1
1
  import { GraphNode } from './graph_node.js';
2
- import '../app.js';
3
2
  import '@zephyr3d/base';
4
3
  import './octree.js';
4
+ import '../app.js';
5
+ import { InstanceBindGroupAllocator, RenderQueue } from '../render/render_queue.js';
5
6
  import '../material/shader/helper.js';
7
+ import '../render/renderer.js';
8
+ import '../render/sky.js';
9
+ import '../render/clipmap.js';
10
+ import '@zephyr3d/device';
11
+ import '../render/watermesh.js';
6
12
  import '../material/lambert.js';
7
13
  import '../material/blinn.js';
8
14
  import '../material/unlit.js';
9
- import '../material/material.js';
10
15
  import '../material/meshmaterial.js';
11
16
  import '../material/grassmaterial.js';
12
17
  import '../material/terrainmaterial.js';
13
18
  import '../material/pbrmr.js';
14
19
  import '../material/pbrsg.js';
15
- import { InstanceBindGroupAllocator, RenderQueue } from '../render/render_queue.js';
16
- import { SceneRenderer } from '../render/renderer.js';
17
- import '../render/sky.js';
18
- import '../render/clipmap.js';
19
- import '@zephyr3d/device';
20
- import '../render/watermesh.js';
21
20
 
22
21
  /**
23
22
  * Batch group node
@@ -25,7 +24,6 @@ import '../render/watermesh.js';
25
24
  */ class BatchGroup extends GraphNode {
26
25
  _renderQueueMap;
27
26
  _bindGroupAllocator;
28
- _transformHandler;
29
27
  _changeTag;
30
28
  /**
31
29
  * Creates an instance of mesh node
@@ -35,38 +33,13 @@ import '../render/watermesh.js';
35
33
  this._renderQueueMap = new WeakMap();
36
34
  this._changeTag = 0;
37
35
  this._bindGroupAllocator = new InstanceBindGroupAllocator();
38
- this._transformHandler = (node)=>{
39
- if (node.isGraphNode() && node.isBatchable()) {
40
- const lightInstanceInfo = node.getInstanceDataBuffer(SceneRenderer.sceneRenderPass);
41
- if (lightInstanceInfo?.bindGroup) {
42
- lightInstanceInfo.bindGroup.buffer.set(node.worldMatrix, lightInstanceInfo.offset);
43
- lightInstanceInfo.bindGroup.dirty = true;
44
- }
45
- const depthInstanceInfo = node.getInstanceDataBuffer(SceneRenderer.depthRenderPass);
46
- if (depthInstanceInfo?.bindGroup) {
47
- depthInstanceInfo.bindGroup.buffer.set(node.worldMatrix, depthInstanceInfo.offset);
48
- depthInstanceInfo.bindGroup.dirty = true;
49
- }
50
- const shadowMapInstanceInfo = node.getInstanceDataBuffer(SceneRenderer.shadowMapRenderPass);
51
- if (shadowMapInstanceInfo?.bindGroup.buffer) {
52
- shadowMapInstanceInfo.bindGroup.buffer.set(node.worldMatrix, shadowMapInstanceInfo.offset);
53
- shadowMapInstanceInfo.bindGroup.dirty = true;
54
- }
55
- }
56
- };
57
36
  this.on('nodeattached', (node)=>{
58
37
  node.iterate((child)=>{
59
38
  if (child.isGraphNode()) {
60
39
  if (!child.isMesh()) {
61
40
  console.error('Only mesh node can be added to batch group');
62
41
  }
63
- child.on('transformchanged', this._transformHandler);
64
42
  child.placeToOctree = false;
65
- if (child.isBatchable()) {
66
- child.setInstanceDataBuffer(SceneRenderer.sceneRenderPass, null, 0);
67
- child.setInstanceDataBuffer(SceneRenderer.depthRenderPass, null, 0);
68
- child.setInstanceDataBuffer(SceneRenderer.shadowMapRenderPass, null, 0);
69
- }
70
43
  }
71
44
  });
72
45
  this._changeTag++;
@@ -74,7 +47,6 @@ import '../render/watermesh.js';
74
47
  this.on('noderemoved', (node)=>{
75
48
  node.iterate((child)=>{
76
49
  if (child.isGraphNode()) {
77
- child.off('transformchanged', this._transformHandler);
78
50
  child.placeToOctree = true;
79
51
  }
80
52
  });
@@ -115,6 +87,7 @@ import '../render/watermesh.js';
115
87
  cullVisitor.visit(node);
116
88
  }
117
89
  });
90
+ queueInfo.queue.end(cullVisitor.camera, true);
118
91
  cullVisitor.frustumCulling = frustumCulling;
119
92
  cullVisitor.renderQueue = renderQueue;
120
93
  }
@@ -1 +1 @@
1
- {"version":3,"file":"batchgroup.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"batchgroup.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,17 +1,16 @@
1
1
  import { Vector4 } from '@zephyr3d/base';
2
- import '../app.js';
3
2
  import './octree.js';
3
+ import '../app.js';
4
+ import '@zephyr3d/device';
4
5
  import '../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/device';
15
14
  import '../render/renderer.js';
16
15
  import { SkyRenderer } from '../render/sky.js';
17
16
  import '../render/clipmap.js';
@@ -1 +1 @@
1
- {"version":3,"file":"environment.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"environment.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -21,7 +21,7 @@ import { SceneNode } from './scene_node.js';
21
21
  /** @internal */ get octreeNode() {
22
22
  return this._octreeNode;
23
23
  }
24
- /** @internal */ set octreeNode(node) {
24
+ set octreeNode(node) {
25
25
  this._octreeNode = node;
26
26
  }
27
27
  /**
@@ -1,4 +1,4 @@
1
- import { Vector4 } from '@zephyr3d/base';
1
+ import { applyMixins, Vector4 } from '@zephyr3d/base';
2
2
  import { GraphNode } from './graph_node.js';
3
3
  import '@zephyr3d/device';
4
4
  import { Application } from '../app.js';
@@ -7,18 +7,18 @@ import '../material/shader/helper.js';
7
7
  import { LambertMaterial } from '../material/lambert.js';
8
8
  import '../material/blinn.js';
9
9
  import '../material/unlit.js';
10
- import '../material/material.js';
10
+ import { QUEUE_OPAQUE } from '../values.js';
11
11
  import '../material/meshmaterial.js';
12
12
  import '../material/grassmaterial.js';
13
13
  import '../material/terrainmaterial.js';
14
14
  import '../material/pbrmr.js';
15
15
  import '../material/pbrsg.js';
16
- import { QUEUE_OPAQUE } from '../values.js';
16
+ import { mixinDrawable } from '../render/drawable_mixin.js';
17
17
 
18
18
  /**
19
19
  * Mesh node
20
20
  * @public
21
- */ class Mesh extends GraphNode {
21
+ */ class Mesh extends applyMixins(GraphNode, mixinDrawable) {
22
22
  /** @internal */ _primitive;
23
23
  /** @internal */ _material;
24
24
  /** @internal */ _castShadow;
@@ -30,7 +30,6 @@ import { QUEUE_OPAQUE } from '../values.js';
30
30
  /** @internal */ _batchable;
31
31
  /** @internal */ _boundingBoxNode;
32
32
  /** @internal */ _instanceColor;
33
- /** @internal */ _instanceBufferInfo;
34
33
  /**
35
34
  * Creates an instance of mesh node
36
35
  * @param scene - The scene to which the mesh node belongs
@@ -44,7 +43,6 @@ import { QUEUE_OPAQUE } from '../values.js';
44
43
  this._invBindMatrix = null;
45
44
  this._instanceHash = null;
46
45
  this._boundingBoxNode = null;
47
- this._instanceBufferInfo = new Map();
48
46
  this._instanceColor = Vector4.zero();
49
47
  this._batchable = Application.instance.deviceType !== 'webgl';
50
48
  this._bboxChangeCallback = this._onBoundingboxChange.bind(this);
@@ -63,7 +61,7 @@ import { QUEUE_OPAQUE } from '../values.js';
63
61
  return `${this._instanceHash}:${this.worldMatrixDet >= 0}`;
64
62
  }
65
63
  /**
66
- * {@inheritDoc BatchDrawable.getInstanceUniformCount}
64
+ * {@inheritDoc BatchDrawable.getInstanceUniforms}
67
65
  */ getInstanceUniforms() {
68
66
  return this.material.$instanceUniforms;
69
67
  }
@@ -175,9 +173,15 @@ import { QUEUE_OPAQUE } from '../values.js';
175
173
  /**
176
174
  * {@inheritDoc Drawable.draw}
177
175
  */ draw(ctx) {
176
+ this.bind(ctx);
178
177
  this.material.draw(this.primitive, ctx);
179
178
  }
180
179
  /**
180
+ * {@inheritDoc Drawable.getMaterial}
181
+ */ getMaterial() {
182
+ return this.material;
183
+ }
184
+ /**
181
185
  * {@inheritDoc Drawable.getBoneMatrices}
182
186
  */ getBoneMatrices() {
183
187
  return this._boneMatrices;
@@ -193,31 +197,6 @@ import { QUEUE_OPAQUE } from '../values.js';
193
197
  // mesh transform should be ignored when skinned
194
198
  return this;
195
199
  }
196
- /**
197
- * {@inheritDoc BatchDrawable.setInstanceDataBuffer}
198
- */ setInstanceDataBuffer(renderPass, bindGroup, offset) {
199
- const info = this._instanceBufferInfo.get(renderPass);
200
- if (!info) {
201
- if (bindGroup) {
202
- this._instanceBufferInfo.set(renderPass, {
203
- bindGroup,
204
- offset
205
- });
206
- }
207
- } else {
208
- if (bindGroup) {
209
- info.bindGroup = bindGroup;
210
- info.offset = offset;
211
- } else {
212
- this._instanceBufferInfo.delete(renderPass);
213
- }
214
- }
215
- }
216
- /**
217
- * {@inheritDoc BatchDrawable.getInstanceDataBuffer}
218
- */ getInstanceDataBuffer(renderPass) {
219
- return this._instanceBufferInfo.get(renderPass) ?? null;
220
- }
221
200
  /** @internal */ computeBoundingVolume(bv) {
222
201
  let bbox;
223
202
  if (this._animatedBoundingBox) {
@@ -1 +1 @@
1
- {"version":3,"file":"mesh.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"mesh.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -520,9 +520,9 @@ var OctreePlacement;
520
520
  }
521
521
  const dim = this._chunks[level].getDimension();
522
522
  const inv_node_size = 1 / this._chunks[level].getNodeSize();
523
- let px = Math.floor((center.x + this._rootSize * 0.5) * inv_node_size);
524
- let py = Math.floor((center.y + this._rootSize * 0.5) * inv_node_size);
525
- let pz = Math.floor((center.z + this._rootSize * 0.5) * inv_node_size);
523
+ const px = Math.floor((center.x + this._rootSize * 0.5) * inv_node_size);
524
+ const py = Math.floor((center.y + this._rootSize * 0.5) * inv_node_size);
525
+ const pz = Math.floor((center.z + this._rootSize * 0.5) * inv_node_size);
526
526
  if (px >= dim || py >= dim || pz >= dim) {
527
527
  return null;
528
528
  }
@@ -1,19 +1,8 @@
1
- import { makeEventTarget, Vector4, Vector3, Ray, nextPowerOf2 } from '@zephyr3d/base';
1
+ import { makeEventTarget, Vector4, Vector3, Ray } from '@zephyr3d/base';
2
2
  import { SceneNode } from './scene_node.js';
3
3
  import { Octree } from './octree.js';
4
- import { OctreeUpdateVisitor } from './octree_update_visitor.js';
5
- import '../material/shader/helper.js';
6
- import '../material/lambert.js';
7
- import '../material/blinn.js';
8
- import '../material/unlit.js';
9
- import { Material } from '../material/material.js';
10
- import '../material/meshmaterial.js';
11
- import '../material/grassmaterial.js';
12
- import '../material/terrainmaterial.js';
13
- import '../material/pbrmr.js';
14
- import '../material/pbrsg.js';
15
- import { Application } from '../app.js';
16
4
  import { RaycastVisitor } from './raycast_visitor.js';
5
+ import { Application } from '../app.js';
17
6
  import { Environment } from './environment.js';
18
7
 
19
8
  /**
@@ -138,10 +127,6 @@ import { Environment } from './environment.js';
138
127
  const frameInfo = Application.instance.device.frameInfo;
139
128
  if (frameInfo.frameCounter !== this._updateFrame) {
140
129
  this._updateFrame = frameInfo.frameCounter;
141
- // uniform buffer garbage collect
142
- if (!Material.getGCOptions().disabled) {
143
- Material.garbageCollect(frameInfo.frameTimestamp);
144
- }
145
130
  for (const an of this._animationSet){
146
131
  an.update();
147
132
  }
@@ -191,18 +176,6 @@ import { Environment } from './environment.js';
191
176
  list.delete(node);
192
177
  }
193
178
  }
194
- if (octree) {
195
- const worldBox = octree.getRootNode().getBox();
196
- if (worldBox) {
197
- const radius = Math.max(Math.abs(worldBox.minPoint.x), Math.abs(worldBox.minPoint.y), Math.abs(worldBox.minPoint.z), Math.abs(worldBox.maxPoint.x), Math.abs(worldBox.maxPoint.y), Math.abs(worldBox.maxPoint.z));
198
- const rootSize = nextPowerOf2(radius * 2);
199
- if (rootSize > octree.getRootSize()) {
200
- octree.initialize(rootSize, octree.getLeafSize());
201
- const v = new OctreeUpdateVisitor(octree);
202
- this._rootNode.traverse(v);
203
- }
204
- }
205
- }
206
179
  }
207
180
  }
208
181
  }
@@ -1 +1 @@
1
- {"version":3,"file":"scene.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"scene.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -53,7 +53,7 @@ import { XForm } from './xform.js';
53
53
  /** @internal */ get placeToOctree() {
54
54
  return this._placeToOctree;
55
55
  }
56
- /** @internal */ set placeToOctree(val) {
56
+ set placeToOctree(val) {
57
57
  if (!!val !== this._placeToOctree) {
58
58
  this._placeToOctree = !!val;
59
59
  if (this.isGraphNode()) {
@@ -125,6 +125,10 @@ import { XForm } from './xform.js';
125
125
  }
126
126
  /**
127
127
  * Iterate self and all of the children
128
+ *
129
+ * @remarks
130
+ * DO NOT remove child duration iteration!
131
+ *
128
132
  * @param callback - callback function that will be called on each node
129
133
  */ iterate(callback) {
130
134
  callback(this);
@@ -293,6 +297,7 @@ import { XForm } from './xform.js';
293
297
  /** @internal */ _detached() {}
294
298
  /** @internal */ notifyHiddenChanged() {
295
299
  this._visibleChanged();
300
+ this.dispatchEvent(this, 'visiblechanged');
296
301
  for (const child of this._children){
297
302
  if (child.showState === 'inherit') {
298
303
  child.notifyHiddenChanged();
@@ -1 +1 @@
1
- {"version":3,"file":"scene_node.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"scene_node.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,30 +1,37 @@
1
- import { nextPowerOf2, Vector2 } from '@zephyr3d/base';
1
+ import { applyMixins, nextPowerOf2, Vector2 } from '@zephyr3d/base';
2
2
  import { Primitive } from '../../render/primitive.js';
3
- import { Application } from '../../app.js';
4
3
  import { GrassMaterial } from '../../material/grassmaterial.js';
4
+ import { mixinDrawable } from '../../render/drawable_mixin.js';
5
5
 
6
- class GrassCluster {
7
- _primitive;
6
+ class GrassClusterBase {
8
7
  _terrain;
8
+ constructor(terrain){
9
+ this._terrain = terrain;
10
+ }
11
+ getXForm() {
12
+ return this._terrain;
13
+ }
14
+ }
15
+ class GrassCluster extends applyMixins(GrassClusterBase, mixinDrawable) {
16
+ _primitive;
9
17
  _numInstances;
10
18
  _material;
11
19
  constructor(device, terrain, baseVertexBuffer, indexBuffer, material, grassData){
20
+ super(terrain);
12
21
  this._primitive = new Primitive();
13
22
  const instanceVertexBuffer = device.createVertexBuffer('tex1_f32x4', grassData);
14
23
  this._primitive.setVertexBuffer(baseVertexBuffer, 'vertex');
15
24
  this._primitive.setVertexBuffer(instanceVertexBuffer, 'instance');
16
25
  this._primitive.setIndexBuffer(indexBuffer);
17
26
  this._primitive.primitiveType = 'triangle-list';
18
- this._terrain = terrain;
19
27
  this._numInstances = grassData.length >> 2;
20
28
  this._material = material;
21
- this._material.stateSet.useRasterizerState().setCullMode('none');
22
29
  }
23
30
  getName() {
24
31
  return 'GrassCluster';
25
32
  }
26
- getXForm() {
27
- return this._terrain;
33
+ getMaterial() {
34
+ return this._material;
28
35
  }
29
36
  getInstanceColor() {
30
37
  return this._terrain.getInstanceColor();
@@ -51,8 +58,7 @@ class GrassCluster {
51
58
  return false;
52
59
  }
53
60
  draw(ctx) {
54
- this._material.alphaToCoverage = Application.instance.device.getFrameBufferSampleCount() > 1;
55
- this._material.alphaCutoff = this._material.alphaToCoverage ? 1 : 0.8;
61
+ this.bind(ctx);
56
62
  this._material.draw(this._primitive, ctx, this._numInstances);
57
63
  }
58
64
  }
@@ -263,5 +269,5 @@ function getPrimitive(device: AbstractDevice): Primitive {
263
269
  }
264
270
  */
265
271
 
266
- export { GrassCluster, GrassManager };
272
+ export { GrassCluster, GrassClusterBase, GrassManager };
267
273
  //# sourceMappingURL=grass.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"grass.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"grass.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}