@zephyr3d/scene 0.1.0 → 0.1.2

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 (60) hide show
  1. package/README.md +46 -0
  2. package/dist/animation/animation.js +28 -28
  3. package/dist/animation/skeleton.js +14 -14
  4. package/dist/animation/usertrack.js +9 -9
  5. package/dist/app.js +31 -31
  6. package/dist/asset/assetmanager.js +50 -50
  7. package/dist/asset/builtin.js +157 -157
  8. package/dist/asset/loaders/dds/dds_loader.js +11 -11
  9. package/dist/asset/loaders/gltf/gltf_loader.js +10 -10
  10. package/dist/asset/loaders/hdr/hdr.js +5 -5
  11. package/dist/asset/loaders/image/tga_Loader.js +3 -3
  12. package/dist/asset/loaders/image/webimage_loader.js +3 -3
  13. package/dist/asset/loaders/loader.js +19 -19
  14. package/dist/asset/model.js +57 -57
  15. package/dist/blitter/blitter.js +35 -35
  16. package/dist/blitter/box.js +24 -24
  17. package/dist/blitter/depthlimitedgaussion.js +3 -3
  18. package/dist/blitter/gaussianblur.js +21 -21
  19. package/dist/camera/camera.js +68 -68
  20. package/dist/index.d.ts +2 -0
  21. package/dist/material/grassmaterial.js +17 -17
  22. package/dist/material/lambert.js +3 -3
  23. package/dist/material/lightmodel.js +362 -362
  24. package/dist/material/material.js +50 -50
  25. package/dist/material/meshmaterial.js +48 -48
  26. package/dist/material/unlit.js +3 -3
  27. package/dist/posteffect/bloom.js +5 -5
  28. package/dist/posteffect/compositor.js +16 -16
  29. package/dist/posteffect/fxaa.js +5 -5
  30. package/dist/posteffect/grayscale.js +5 -5
  31. package/dist/posteffect/posteffect.js +42 -42
  32. package/dist/posteffect/sao.js +5 -5
  33. package/dist/posteffect/tonemap.js +5 -5
  34. package/dist/posteffect/water.js +6 -6
  35. package/dist/render/cull_visitor.js +12 -12
  36. package/dist/render/depth_pass.js +8 -8
  37. package/dist/render/envlight.js +104 -104
  38. package/dist/render/render_queue.js +33 -33
  39. package/dist/render/renderpass.js +18 -18
  40. package/dist/render/renderscheme.js +14 -14
  41. package/dist/render/scatteringlut.js +3 -3
  42. package/dist/render/sky.js +38 -38
  43. package/dist/render/temporalcache.js +4 -4
  44. package/dist/render/watermesh.js +5 -5
  45. package/dist/scene/graph_node.js +25 -25
  46. package/dist/scene/octree.js +191 -191
  47. package/dist/scene/scene.js +37 -37
  48. package/dist/scene/terrain/grass.js +27 -27
  49. package/dist/scene/terrain/quadtree.js +45 -45
  50. package/dist/shaders/framework.js +161 -161
  51. package/dist/shaders/lighting.js +7 -7
  52. package/dist/shaders/noise.js +43 -43
  53. package/dist/shadow/shadowmapper.js +76 -76
  54. package/dist/shadow/ssm.js +34 -34
  55. package/dist/utility/bounding_volume.js +30 -27
  56. package/dist/utility/bounding_volume.js.map +1 -1
  57. package/dist/utility/shprojection.js +14 -14
  58. package/package.json +70 -70
  59. package/dist/material/mixins/texture.js +0 -110
  60. package/dist/material/mixins/texture.js.map +0 -1
@@ -26,9 +26,9 @@ import '../render/watermesh.js';
26
26
  const tmpMatrix = new Matrix4x4();
27
27
  const tmpFrustum = new Frustum(Matrix4x4.identity());
28
28
  // const zeroPosition = Vector3.zero();
29
- /**
30
- * The shadow map generator
31
- * @public
29
+ /**
30
+ * The shadow map generator
31
+ * @public
32
32
  */ class ShadowMapper {
33
33
  /** @internal */ static _snapMatrix = new Matrix4x4();
34
34
  /** @internal */ static _target = new Vector3();
@@ -54,9 +54,9 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
54
54
  /** @internal */ _esmBlurKernelSize;
55
55
  /** @internal */ _esmBlurRadius;
56
56
  /** @internal */ _esmDepthScale;
57
- /**
58
- * Creates an instance of ShadowMapper
59
- * @param light - The light that is used to generate shadow map
57
+ /**
58
+ * Creates an instance of ShadowMapper
59
+ * @param light - The light that is used to generate shadow map
60
60
  */ constructor(light){
61
61
  this._light = light;
62
62
  this._config = {
@@ -159,14 +159,14 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
159
159
  this.applyMode(this._shadowMode);
160
160
  }
161
161
  }
162
- /** Generated shadow map */ /*
163
- get shadowMap(): ShadowMapType {
164
- return (this._impl.getShadowMap(this) ?? this._framebuffer?.getColorAttachments()[0] ?? null) as ShadowMapType;
165
- }
166
- */ /** Sampler of the shadow map */ /*
167
- get shadowMapSampler(): TextureSampler {
168
- return this._impl.getShadowMapSampler(this);
169
- }
162
+ /** Generated shadow map */ /*
163
+ get shadowMap(): ShadowMapType {
164
+ return (this._impl.getShadowMap(this) ?? this._framebuffer?.getColorAttachments()[0] ?? null) as ShadowMapType;
165
+ }
166
+ */ /** Sampler of the shadow map */ /*
167
+ get shadowMapSampler(): TextureSampler {
168
+ return this._impl.getShadowMapSampler(this);
169
+ }
170
170
  */ /** @internal */ getShaderHash(shadowMapParams) {
171
171
  return `${shadowMapParams.impl.constructor.name}_${shadowMapParams.impl.getShaderHash()}_${shadowMapParams.lightType}_${shadowMapParams.shadowMap.target}_${Number(shadowMapParams.numShadowCascades > 1)}_${Number(Application.instance.device.getDeviceCaps().textureCaps.getTextureFormatInfo(shadowMapParams.shadowMap.format).filterable)}`;
172
172
  }
@@ -411,68 +411,68 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
411
411
  center.setXYZ((rx - tx) * 2 / this.shadowMapSize, (ry - ty) * 2 / this.shadowMapSize, 0);
412
412
  cropMatrix.translation(center);
413
413
  }
414
- /*
415
- const minx = frustumMin.x;
416
- const maxx = frustumMax.x;
417
- const miny = frustumMin.y;
418
- const maxy = frustumMax.y;
419
- const minz = frustumMin.z;
420
- const maxz = frustumMax.z;
421
- const texelSizeW = (maxx - minx) / this.shadowMapSize;
422
- const texelSizeH = (maxy - miny) / this.shadowMapSize;
423
- const cx = Math.floor((minx + maxx) / 2 / texelSizeW) * texelSizeW;
424
- const cy = Math.floor((miny + maxy) / 2 / texelSizeH) * texelSizeH;
425
- const cz = (minz + maxz) / 2;
426
- const hx = Math.floor(((maxx - minx) * (expand + 0.5)) / texelSizeW) * texelSizeW;
427
- const hy = Math.floor(((maxy - miny) * (expand + 0.5)) / texelSizeH) * texelSizeH;
428
- lightCamera.position.setXYZ(cx, cy, cz);
429
- lightCamera.setOrtho(
430
- -hx,
431
- hx,
432
- -hy,
433
- hy,
434
- sceneMax.z - maxz,
435
- sceneMax.z - minz + 1
436
- );
437
- if (cropMatrix) {
438
- // compute crop matrix
439
- let clipMaxX = 0,
440
- clipMaxY = 0;
441
- let clipMinX = Number.MAX_VALUE,
442
- clipMinY = Number.MAX_VALUE;
443
- frustum.corners.forEach((p) => {
444
- const clipPos = lightCamera.viewProjectionMatrix.transformPoint(p);
445
- clipPos.x = Math.min(1, Math.max(-1, clipPos.x / clipPos.w));
446
- clipPos.y = Math.min(1, Math.max(-1, clipPos.y / clipPos.w));
447
- if (clipPos.x > clipMaxX) {
448
- clipMaxX = clipPos.x;
449
- }
450
- if (clipPos.x < clipMinX) {
451
- clipMinX = clipPos.x;
452
- }
453
- if (clipPos.y > clipMaxY) {
454
- clipMaxY = clipPos.y;
455
- }
456
- if (clipPos.y < clipMinY) {
457
- clipMinY = clipPos.y;
458
- }
459
- });
460
- const clipW = clipMaxX - clipMinX;
461
- const clipH = clipMaxY - clipMinY;
462
- clipMinX -= expand * clipW;
463
- clipMinY -= expand * clipH;
464
- clipMaxX += expand * clipW;
465
- clipMaxY += expand * clipH;
466
- const scaleX = 2 / (clipMaxX - clipMinX);
467
- const scaleY = 2 / (clipMaxY - clipMinY);
468
- const offsetX = -0.5 * (clipMaxX + clipMinX) * scaleX;
469
- const offsetY = -0.5 * (clipMaxY + clipMinY) * scaleY;
470
- cropMatrix.identity();
471
- cropMatrix.m00 = scaleX;
472
- cropMatrix.m11 = scaleY;
473
- cropMatrix.m03 = offsetX;
474
- cropMatrix.m13 = offsetY;
475
- }
414
+ /*
415
+ const minx = frustumMin.x;
416
+ const maxx = frustumMax.x;
417
+ const miny = frustumMin.y;
418
+ const maxy = frustumMax.y;
419
+ const minz = frustumMin.z;
420
+ const maxz = frustumMax.z;
421
+ const texelSizeW = (maxx - minx) / this.shadowMapSize;
422
+ const texelSizeH = (maxy - miny) / this.shadowMapSize;
423
+ const cx = Math.floor((minx + maxx) / 2 / texelSizeW) * texelSizeW;
424
+ const cy = Math.floor((miny + maxy) / 2 / texelSizeH) * texelSizeH;
425
+ const cz = (minz + maxz) / 2;
426
+ const hx = Math.floor(((maxx - minx) * (expand + 0.5)) / texelSizeW) * texelSizeW;
427
+ const hy = Math.floor(((maxy - miny) * (expand + 0.5)) / texelSizeH) * texelSizeH;
428
+ lightCamera.position.setXYZ(cx, cy, cz);
429
+ lightCamera.setOrtho(
430
+ -hx,
431
+ hx,
432
+ -hy,
433
+ hy,
434
+ sceneMax.z - maxz,
435
+ sceneMax.z - minz + 1
436
+ );
437
+ if (cropMatrix) {
438
+ // compute crop matrix
439
+ let clipMaxX = 0,
440
+ clipMaxY = 0;
441
+ let clipMinX = Number.MAX_VALUE,
442
+ clipMinY = Number.MAX_VALUE;
443
+ frustum.corners.forEach((p) => {
444
+ const clipPos = lightCamera.viewProjectionMatrix.transformPoint(p);
445
+ clipPos.x = Math.min(1, Math.max(-1, clipPos.x / clipPos.w));
446
+ clipPos.y = Math.min(1, Math.max(-1, clipPos.y / clipPos.w));
447
+ if (clipPos.x > clipMaxX) {
448
+ clipMaxX = clipPos.x;
449
+ }
450
+ if (clipPos.x < clipMinX) {
451
+ clipMinX = clipPos.x;
452
+ }
453
+ if (clipPos.y > clipMaxY) {
454
+ clipMaxY = clipPos.y;
455
+ }
456
+ if (clipPos.y < clipMinY) {
457
+ clipMinY = clipPos.y;
458
+ }
459
+ });
460
+ const clipW = clipMaxX - clipMinX;
461
+ const clipH = clipMaxY - clipMinY;
462
+ clipMinX -= expand * clipW;
463
+ clipMinY -= expand * clipH;
464
+ clipMaxX += expand * clipW;
465
+ clipMaxY += expand * clipH;
466
+ const scaleX = 2 / (clipMaxX - clipMinX);
467
+ const scaleY = 2 / (clipMaxY - clipMinY);
468
+ const offsetX = -0.5 * (clipMaxX + clipMinX) * scaleX;
469
+ const offsetY = -0.5 * (clipMaxY + clipMinY) * scaleY;
470
+ cropMatrix.identity();
471
+ cropMatrix.m00 = scaleX;
472
+ cropMatrix.m11 = scaleY;
473
+ cropMatrix.m03 = offsetX;
474
+ cropMatrix.m13 = offsetY;
475
+ }
476
476
  */ }
477
477
  /** @internal */ static fetchShadowMapParams() {
478
478
  if (this._shadowMapParams.length > 0) {
@@ -53,40 +53,40 @@ import { computeShadowMapDepth } from '../shaders/shadow.js';
53
53
  }
54
54
  computeShadowMapDepth(shadowMapParams, scope) {
55
55
  return computeShadowMapDepth(scope, shadowMapParams.shadowMap.format);
56
- /*
57
- if (this.useNativeShadowMap(shadowMapParams)) {
58
- return scope.$builder.vec4(
59
- scope.$builder.emulateDepthClamp
60
- ? scope.$builder.clamp(scope.$inputs.clamppedDepth, 0, 1)
61
- : scope.$builtins.fragCoord.z,
62
- 0,
63
- 0,
64
- 1
65
- );
66
- } else {
67
- const pb = scope.$builder;
68
- let depth: PBShaderExp = null;
69
- if (shadowMapParams.lightType === LIGHT_TYPE_DIRECTIONAL) {
70
- depth = pb.emulateDepthClamp
71
- ? pb.clamp(scope.$inputs.clamppedDepth, 0, 1)
72
- : scope.$builtins.fragCoord.z;
73
- } else if (shadowMapParams.lightType === LIGHT_TYPE_POINT) {
74
- const lightSpacePos = pb.mul(
75
- ShaderFramework.getLightViewMatrixForShadow(scope),
76
- ShaderFramework.getWorldPosition(scope)
77
- );
78
- depth = pb.div(pb.length(lightSpacePos.xyz), ShaderFramework.getLightPositionAndRangeForShadow(scope).w);
79
- } else if (shadowMapParams.lightType === LIGHT_TYPE_SPOT) {
80
- const lightSpacePos = pb.mul(
81
- ShaderFramework.getLightViewMatrixForShadow(scope),
82
- ShaderFramework.getWorldPosition(scope)
83
- );
84
- depth = pb.min(pb.div(pb.neg(lightSpacePos.z), ShaderFramework.getLightPositionAndRangeForShadow(scope).w), 1);
85
- }
86
- return shadowMapParams.shadowMap.format === 'rgba8unorm'
87
- ? encodeNormalizedFloatToRGBA(scope, depth)
88
- : pb.vec4(depth, 0, 0, 1);
89
- }
56
+ /*
57
+ if (this.useNativeShadowMap(shadowMapParams)) {
58
+ return scope.$builder.vec4(
59
+ scope.$builder.emulateDepthClamp
60
+ ? scope.$builder.clamp(scope.$inputs.clamppedDepth, 0, 1)
61
+ : scope.$builtins.fragCoord.z,
62
+ 0,
63
+ 0,
64
+ 1
65
+ );
66
+ } else {
67
+ const pb = scope.$builder;
68
+ let depth: PBShaderExp = null;
69
+ if (shadowMapParams.lightType === LIGHT_TYPE_DIRECTIONAL) {
70
+ depth = pb.emulateDepthClamp
71
+ ? pb.clamp(scope.$inputs.clamppedDepth, 0, 1)
72
+ : scope.$builtins.fragCoord.z;
73
+ } else if (shadowMapParams.lightType === LIGHT_TYPE_POINT) {
74
+ const lightSpacePos = pb.mul(
75
+ ShaderFramework.getLightViewMatrixForShadow(scope),
76
+ ShaderFramework.getWorldPosition(scope)
77
+ );
78
+ depth = pb.div(pb.length(lightSpacePos.xyz), ShaderFramework.getLightPositionAndRangeForShadow(scope).w);
79
+ } else if (shadowMapParams.lightType === LIGHT_TYPE_SPOT) {
80
+ const lightSpacePos = pb.mul(
81
+ ShaderFramework.getLightViewMatrixForShadow(scope),
82
+ ShaderFramework.getWorldPosition(scope)
83
+ );
84
+ depth = pb.min(pb.div(pb.neg(lightSpacePos.z), ShaderFramework.getLightPositionAndRangeForShadow(scope).w), 1);
85
+ }
86
+ return shadowMapParams.shadowMap.format === 'rgba8unorm'
87
+ ? encodeNormalizedFloatToRGBA(scope, depth)
88
+ : pb.vec4(depth, 0, 0, 1);
89
+ }
90
90
  */ }
91
91
  computeShadowCSM(shadowMapParams, scope, shadowVertex, NdotL, split) {
92
92
  const funcNameComputeShadowCSM = 'lib_computeShadowCSM';
@@ -1,14 +1,17 @@
1
1
  import { AABB, Frustum, ClipState } from '@zephyr3d/base';
2
2
  import { AABBTree } from './aabbtree.js';
3
3
 
4
- /**
5
- * The bounding box class
6
- * @public
4
+ /**
5
+ * The bounding box class
6
+ * @public
7
7
  */ class BoundingBox extends AABB {
8
8
  constructor(arg0, arg1){
9
9
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
10
  super(arg0, arg1);
11
11
  }
12
+ /** {@inheritDoc BoundingVolume.behindPlane} */ behindPlane(plane) {
13
+ return this.toAABB().behindPlane(plane);
14
+ }
12
15
  /** {@inheritDoc BoundingVolume.clone} */ clone() {
13
16
  return new BoundingBox(this);
14
17
  }
@@ -22,9 +25,9 @@ import { AABBTree } from './aabbtree.js';
22
25
  return this;
23
26
  }
24
27
  }
25
- /**
26
- * Bounding box tree
27
- * @public
28
+ /**
29
+ * Bounding box tree
30
+ * @public
28
31
  */ class BoundingBoxTree extends AABBTree {
29
32
  constructor(arg){
30
33
  super(arg);
@@ -51,27 +54,27 @@ import { AABBTree } from './aabbtree.js';
51
54
  /** {@inheritDoc BoundingVolume.toAABB} */ toAABB() {
52
55
  return this.getTopLevelAABB();
53
56
  }
54
- } /*
55
- export class BoundingFrustum implements BoundingVolume {
56
- protected _frustum: Frustum;
57
- constructor ();
58
- constructor (other: BoundingFrustum|Frustum|Matrix4x4);
59
- constructor (arg0?: BoundingFrustum|Frustum|Matrix4x4) {
60
- if (arg0 instanceof BoundingFrustum) {
61
- this._frustum = arg0._frustum ? new Frustum (arg0._frustum) : null;
62
- } else if (arg0 instanceof Frustum) {
63
- this._frustum = new Frustum (arg0);
64
- } else if (arg0 instanceof Matrix4x4) {
65
- this._frustum = new Frustum (arg0);
66
- } else {
67
- this._frustum = null;
68
- }
69
- }
70
- clone (): BoundingVolume {
71
- return new BoundingFrustum (this);
72
- }
73
- transform (matrix: Matrix4x4)
74
- }
57
+ } /*
58
+ export class BoundingFrustum implements BoundingVolume {
59
+ protected _frustum: Frustum;
60
+ constructor ();
61
+ constructor (other: BoundingFrustum|Frustum|Matrix4x4);
62
+ constructor (arg0?: BoundingFrustum|Frustum|Matrix4x4) {
63
+ if (arg0 instanceof BoundingFrustum) {
64
+ this._frustum = arg0._frustum ? new Frustum (arg0._frustum) : null;
65
+ } else if (arg0 instanceof Frustum) {
66
+ this._frustum = new Frustum (arg0);
67
+ } else if (arg0 instanceof Matrix4x4) {
68
+ this._frustum = new Frustum (arg0);
69
+ } else {
70
+ this._frustum = null;
71
+ }
72
+ }
73
+ clone (): BoundingVolume {
74
+ return new BoundingFrustum (this);
75
+ }
76
+ transform (matrix: Matrix4x4)
77
+ }
75
78
  */
76
79
 
77
80
  export { BoundingBox, BoundingBoxTree };
@@ -1 +1 @@
1
- {"version":3,"file":"bounding_volume.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"bounding_volume.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -300,13 +300,13 @@ async function doProjectCubemap(srcTexture, coeff) {
300
300
  }
301
301
  return result;
302
302
  }
303
- /**
304
- * Projects a function represented in a cubemap into spherical harmonics using GPU
305
- *
306
- * @param input - The input cubemap
307
- * @returns The evaluated SH data
308
- *
309
- * @public
303
+ /**
304
+ * Projects a function represented in a cubemap into spherical harmonics using GPU
305
+ *
306
+ * @param input - The input cubemap
307
+ * @returns The evaluated SH data
308
+ *
309
+ * @public
310
310
  */ async function projectCubemap(tex) {
311
311
  const device = Application.instance.device;
312
312
  const srcTex = tex;
@@ -364,13 +364,13 @@ function directionFromCubemapTexel(face, x, y, invSize) {
364
364
  }
365
365
  return dir.inplaceNormalize();
366
366
  }
367
- /**
368
- * Projects a function represented in a cubemap into spherical harmonics using CPU
369
- *
370
- * @param input - The input cubemap
371
- * @returns The evaluated SH data
372
- *
373
- * @public
367
+ /**
368
+ * Projects a function represented in a cubemap into spherical harmonics using CPU
369
+ *
370
+ * @param input - The input cubemap
371
+ * @returns The evaluated SH data
372
+ *
373
+ * @public
374
374
  */ async function projectCubemapCPU(input) {
375
375
  let srcTex = input;
376
376
  const device = Application.instance.device;
package/package.json CHANGED
@@ -1,70 +1,70 @@
1
- {
2
- "name": "@zephyr3d/scene",
3
- "version": "0.1.0",
4
- "description": "scene system for zephyr3d",
5
- "homepage": "https://github.com/gavinyork/zephyr3d#readme",
6
- "type": "module",
7
- "main": "./dist/index.js",
8
- "module": "./dist/index.js",
9
- "types": "./dist/index.d.ts",
10
- "files": [
11
- "**/*.js",
12
- "**/*.d.ts",
13
- "**/*.js.map"
14
- ],
15
- "sideEffects": false,
16
- "repository": {
17
- "type": "git",
18
- "url": "git+https://github.com/gavinyork/zephyr3d.git"
19
- },
20
- "scripts": {
21
- "clean": "shx rm -rf ./dist .tsbuildinfo",
22
- "tsc": "tsc -p . --noEmit",
23
- "build": "cross-env NODE_OPTIONS=--max_old_space_size=8192 rollup -c --silent"
24
- },
25
- "keywords": [
26
- "javascript",
27
- "3d",
28
- "rendering",
29
- "engine",
30
- "webgl",
31
- "webgpu",
32
- "canvas",
33
- "zephyr3d",
34
- "device"
35
- ],
36
- "license": "MIT",
37
- "bugs": {
38
- "url": "https://github.com/gavinyork/zephyr3d/issues"
39
- },
40
- "engines": {
41
- "node": ">=16.18.0"
42
- },
43
- "devDependencies": {
44
- "@babel/core": "^7.20.12",
45
- "@babel/preset-env": "^7.20.2",
46
- "@rollup/plugin-babel": "^6.0.3",
47
- "@rollup/plugin-node-resolve": "^15.0.1",
48
- "@rollup/plugin-strip": "^3.0.2",
49
- "@rollup/plugin-terser": "^0.4.0",
50
- "@rollup/pluginutils": "^5.0.2",
51
- "@swc/core": "^1.3.62",
52
- "rollup-plugin-swc3": "^0.8.2",
53
- "rollup": "^3.15.0",
54
- "rollup-plugin-dts": "^5.2.0",
55
- "rollup-plugin-copy": "^3.4.0",
56
- "rollup-plugin-typescript2": "^0.34.1",
57
- "shx": "^0.3.4",
58
- "cross-env": "^7.0.3",
59
- "typescript": "^5.1.3",
60
- "@zephyr3d/base": "workspace:^0.1.0",
61
- "@zephyr3d/device": "workspace:^0.1.0"
62
- },
63
- "peerDependencies": {
64
- "@zephyr3d/base": "workspace:^0.1.0",
65
- "@zephyr3d/device": "workspace:^0.1.0"
66
- },
67
- "dependencies": {
68
- "@webgpu/types": "^0.1.31"
69
- }
70
- }
1
+ {
2
+ "name": "@zephyr3d/scene",
3
+ "version": "0.1.2",
4
+ "description": "scene system for zephyr3d",
5
+ "homepage": "https://github.com/gavinyork/zephyr3d#readme",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "files": [
11
+ "**/*.js",
12
+ "**/*.d.ts",
13
+ "**/*.js.map"
14
+ ],
15
+ "sideEffects": false,
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/gavinyork/zephyr3d.git"
19
+ },
20
+ "keywords": [
21
+ "javascript",
22
+ "3d",
23
+ "rendering",
24
+ "engine",
25
+ "webgl",
26
+ "webgpu",
27
+ "canvas",
28
+ "zephyr3d",
29
+ "device"
30
+ ],
31
+ "license": "MIT",
32
+ "bugs": {
33
+ "url": "https://github.com/gavinyork/zephyr3d/issues"
34
+ },
35
+ "engines": {
36
+ "node": ">=16.18.0"
37
+ },
38
+ "devDependencies": {
39
+ "@babel/core": "^7.20.12",
40
+ "@babel/preset-env": "^7.20.2",
41
+ "@rollup/plugin-babel": "^6.0.3",
42
+ "@rollup/plugin-node-resolve": "^15.0.1",
43
+ "@rollup/plugin-strip": "^3.0.2",
44
+ "@rollup/plugin-terser": "^0.4.0",
45
+ "@rollup/pluginutils": "^5.0.2",
46
+ "@swc/core": "^1.3.62",
47
+ "@zephyr3d/base": "^0.1.2",
48
+ "@zephyr3d/device": "^0.1.2",
49
+ "cross-env": "^7.0.3",
50
+ "rollup": "^3.15.0",
51
+ "rollup-plugin-copy": "^3.4.0",
52
+ "rollup-plugin-dts": "^5.2.0",
53
+ "rollup-plugin-swc3": "^0.8.2",
54
+ "rollup-plugin-typescript2": "^0.34.1",
55
+ "shx": "^0.3.4",
56
+ "typescript": "^5.1.3"
57
+ },
58
+ "peerDependencies": {
59
+ "@zephyr3d/base": "^0.1.2",
60
+ "@zephyr3d/device": "^0.1.2"
61
+ },
62
+ "dependencies": {
63
+ "@webgpu/types": "^0.1.31"
64
+ },
65
+ "scripts": {
66
+ "clean": "shx rm -rf ./dist .tsbuildinfo",
67
+ "tsc": "tsc -p . --noEmit",
68
+ "build": "cross-env NODE_OPTIONS=--max_old_space_size=8192 rollup -c --silent"
69
+ }
70
+ }
@@ -1,110 +0,0 @@
1
- function mixinTextureProps(name) {
2
- return function(BaseCls) {
3
- const capName = `${name[0].toUpperCase()}${name.slice(1)}`;
4
- const upperName = name.toUpperCase();
5
- const id = `mixinTexture${capName}`;
6
- const feature = `FEATURE_TEXTURE_${upperName}`;
7
- const featureTexIndex = `FEATURE_TEXTURE_TEXCOORD_INDEX_${upperName}`;
8
- const featureTexMatrix = `FEATURE_TEXTURE_TEXCOORD_MATRIX_${upperName}`;
9
- if (BaseCls[id]) {
10
- return BaseCls;
11
- }
12
- const cls = class extends BaseCls {
13
- constructor(...args){
14
- super(...args);
15
- let textureValue = null;
16
- let textureSampler = null;
17
- let textureCoordIndex = 0;
18
- let textureCoordMatrix = null;
19
- this[`get${capName}TextureUniform`] = function(scope) {
20
- return scope.$builder.shaderKind === 'fragment' ? scope[`kk${capName}Tex`] : null;
21
- };
22
- this[`get${capName}TexCoord`] = function(scope) {
23
- return scope.$builder.shaderKind === 'fragment' ? scope[`kk${capName}TexCoord`] : scope.$outputs[`kk${capName}TexCoord`];
24
- };
25
- Object.defineProperty(this, `${name}Texture`, {
26
- get: ()=>textureValue,
27
- set: (newValue)=>{
28
- if (textureValue !== newValue) {
29
- textureValue = newValue ?? null;
30
- this.useFeature(feature, !!textureValue);
31
- if (textureValue) {
32
- this.useFeature(featureTexIndex, textureCoordIndex);
33
- this.useFeature(featureTexMatrix, !!textureCoordMatrix);
34
- this.optionChanged(false);
35
- }
36
- }
37
- textureValue = newValue;
38
- },
39
- enumerable: true,
40
- configurable: true
41
- });
42
- Object.defineProperty(this, `${name}TextureSampler`, {
43
- get: ()=>textureSampler,
44
- set: (newValue)=>null,
45
- enumerable: true,
46
- configurable: true
47
- });
48
- Object.defineProperty(this, `${name}TexCoordIndex`, {
49
- get: ()=>textureCoordMatrix,
50
- set: (newValue)=>{
51
- if (textureCoordMatrix !== newValue) {
52
- textureCoordMatrix = newValue;
53
- if (textureValue) {
54
- this.useFeature(featureTexMatrix, !!textureCoordMatrix);
55
- }
56
- }
57
- },
58
- enumerable: true,
59
- configurable: true
60
- });
61
- Object.defineProperty(this, `${name}TexCoordMatrix`, {
62
- get: ()=>textureCoordIndex,
63
- set: (newValue)=>{
64
- if (textureCoordIndex !== newValue) {
65
- textureCoordIndex = newValue;
66
- if (textureValue) {
67
- this.useFeature(featureTexIndex, textureCoordIndex);
68
- }
69
- }
70
- },
71
- enumerable: true,
72
- configurable: true
73
- });
74
- }
75
- vertexShader(scope, ctx) {
76
- super.vertexShader(scope, ctx);
77
- if (this.needFragmentColor(ctx)) {
78
- const pb = scope.$builder;
79
- if (this.featureUsed(feature, ctx.renderPass.type)) {
80
- const semantic = `texCoord${this[`${name}TexCoordIndex`]}`;
81
- if (!scope.$getVertexAttrib(semantic)) {
82
- scope.$inputs[semantic] = pb.vec2().attrib(semantic);
83
- }
84
- if (this.featureUsed(featureTexMatrix, ctx.renderPass.type)) {
85
- scope.$g[`kk${capName}TextureMatrix`] = pb.mat4().uniform(2);
86
- scope.$outputs[`kk${capName}TexCoord`] = pb.mul(scope[`kk${capName}TextureMatrix`], pb.vec4(scope.$inputs[semantic], 0, 1)).xy;
87
- } else {
88
- scope.$outputs[`kk${capName}TexCoord`] = scope.$inputs[semantic];
89
- }
90
- }
91
- }
92
- }
93
- fragmentShader(scope, ctx) {
94
- super.fragmentShader(scope, ctx);
95
- if (this.needFragmentColor(ctx)) {
96
- const pb = scope.$builder;
97
- if (this.featureUsed(feature, ctx.renderPass.type)) {
98
- scope.$g[`kk${capName}Tex`] = pb.tex2D().uniform(2);
99
- }
100
- }
101
- }
102
- };
103
- cls[id] = true;
104
- cls[`FEATURE_TEXTURE_${upperName}`] = feature;
105
- return cls;
106
- };
107
- }
108
-
109
- export { mixinTextureProps };
110
- //# sourceMappingURL=texture.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"texture.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}