@needle-tools/engine 4.17.0-alpha.2 → 4.17.0-alpha.3

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.
@@ -2,15 +2,17 @@ import { Box3, BufferAttribute } from 'three';
2
2
  import { MeshBVH } from 'three-mesh-bvh';
3
3
  // Modified according to https://github.com/gkjohnson/three-mesh-bvh/issues/636#issuecomment-2209571751
4
4
  import { WorkerBase } from "three-mesh-bvh/src/workers/utils/WorkerBase.js";
5
- // Use Vite's ?worker import to get a Worker constructor that works correctly
6
- // in both dev (raw-served) and optimized (pre-bundled) contexts.
7
- // The previous `new URL('...', import.meta.url)` pattern broke when the file
8
- // was pre-bundled because the bundler resolved the URL relative to the source
9
- // file path rather than as a bare module specifier.
10
- import GenerateBVHWorker from 'three-mesh-bvh/src/workers/generateMeshBVH.worker.js?worker';
11
5
  export class GenerateMeshBVHWorker extends WorkerBase {
12
6
  constructor() {
13
- super(new GenerateBVHWorker());
7
+ // Worker loading: we use `new URL(specifier, import.meta.url)` + `new Worker(url)`.
8
+ // We can NOT use the Vite `?worker` import suffix (`import W from '...?worker'`) because
9
+ // that breaks pre-bundling: the ?worker query is a Vite-specific convention that doesn't
10
+ // survive the optimizer, and the issue was closed as NOT_PLANNED (vitejs/vite#10837).
11
+ // The `new URL()` pattern works in Vite 8+ thanks to PR #21434 which correctly rebases
12
+ // relative URL paths inside pre-bundled dependencies. This lets us keep three-mesh-bvh
13
+ // in optimizeDeps (no exclude needed), avoiding duplicate three.js instances.
14
+ // https://linear.app/needle/issue/NE-6572
15
+ super(new Worker(new URL('three-mesh-bvh/src/workers/generateMeshBVH.worker.js', import.meta.url), { type: 'module' }));
14
16
  this.name = 'GenerateMeshBVHWorker';
15
17
  }
16
18
  runTask(worker, geometry, options = {}) {
@@ -1 +1 @@
1
- {"version":3,"file":"GenerateMeshBVHWorker.js","sourceRoot":"","sources":["../../../../../src/engine/physics/workers/mesh-bvh/GenerateMeshBVHWorker.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,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;YAC3D,MAAM,QAAQ,GAAG,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC;YACpD,MAAM,YAAY,GAAG,CAAE,QAAQ,CAAE,CAAC;YAClC,IAAK,KAAK,EAAG,CAAC;gBAEb,YAAY,CAAC,IAAI,CAAE,KAAK,CAAE,CAAC;YAE5B,CAAC;YAED,MAAM,CAAC,WAAW,CAAE;gBAEnB,KAAK;gBACL,QAAQ;gBACR,OAAO,EAAE;oBACR,GAAG,OAAO;oBACV,UAAU,EAAE,IAAI;oBAChB,wBAAwB,EAAE,OAAO,CAAE,OAAO,CAAC,UAAU,CAAE;oBACvD,MAAM,EAAE,CAAE,GAAI,QAAQ,CAAC,MAAM,CAAE;iBAC/B;aAED,EAAE,YAAY,CAAC,GAAG,CAAE,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAE,CAAC,MAAM,CAAE,CAAC,CAAC,EAAE,CAAC,CAAE,OAAO,iBAAiB,KAAK,WAAW,CAAE,IAAI,CAAE,CAAE,CAAC,YAAY,iBAAiB,CAAE,CAAE,CAAE,CAAC;QAEhJ,CAAC,CAAE,CAAC;IAEL,CAAC;CAED"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/engine",
3
- "version": "4.17.0-alpha.2",
3
+ "version": "4.17.0-alpha.3",
4
4
  "description": "Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.",
5
5
  "main": "dist/needle-engine.min.js",
6
6
  "exports": {
@@ -1,6 +1,7 @@
1
1
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
2
2
  import { dirname, join } from "path";
3
3
  import { fileURLToPath } from "url";
4
+ import { needleLog } from "./logging.js";
4
5
 
5
6
  const __filename = fileURLToPath(import.meta.url);
6
7
  const __dirname = dirname(__filename);
@@ -43,9 +44,11 @@ function writeSkill(claudeDir) {
43
44
  }
44
45
  const skillPath = join(skillDir, "SKILL.md");
45
46
  const templatePath = join(__dirname, "../../SKILL.md");
46
- const content = readFileSync(templatePath, "utf8");
47
- writeFileSync(skillPath, content, "utf8");
48
- return skillPath;
47
+ if (existsSync(skillPath)) {
48
+ const content = readFileSync(templatePath, "utf8");
49
+ writeFileSync(skillPath, content, "utf8");
50
+ return skillPath;
51
+ }
49
52
  }
50
53
 
51
54
  function installClaudeSkill() {
@@ -53,5 +56,5 @@ function installClaudeSkill() {
53
56
  if (!existsSync(claudeDir)) return; // only install if developer uses Claude Code
54
57
 
55
58
  const path = writeSkill(claudeDir);
56
- console.log(`[${pluginName}] Installed Needle Engine Claude skill → ${path}`);
59
+ if (path) needleLog(`[${pluginName}] Installed Needle Engine Claude skill → ${path}`);
57
60
  }
@@ -44,14 +44,18 @@ export function needleDependencies(command, config, userSettings) {
44
44
  config: (config, env) => {
45
45
  handleOptimizeDeps(config);
46
46
  handleManualChunks(config);
47
+ // Ensure all imports of three resolve to the same copy
48
+ if (!config.resolve) config.resolve = {};
49
+ if (!config.resolve.dedupe) config.resolve.dedupe = [];
50
+ if (!config.resolve.dedupe.includes('three')) {
51
+ config.resolve.dedupe.push('three');
52
+ }
47
53
  },
48
54
  },
49
55
  ]
50
56
  }
51
57
 
52
58
  const excludeDependencies = [
53
- "three-mesh-bvh",
54
- "@needle-tools/gltf-progressive"
55
59
  ]
56
60
 
57
61
  /**
@@ -76,15 +80,6 @@ function handleOptimizeDeps(config) {
76
80
  needleLog("needle-dependencies", `Adding ${dep} to the optimizeDeps.exclude array to support workers.`);
77
81
  config.optimizeDeps.exclude.push(dep);
78
82
 
79
- // When excluding a dep, its imports of shared deps (like three)
80
- // bypass the optimizer and create duplicate module instances.
81
- // Force-include shared deps so they use the pre-bundled version.
82
- if (!config.optimizeDeps.include) config.optimizeDeps.include = [];
83
- const sharedDep = `${dep} > three`;
84
- if (!config.optimizeDeps.include.includes(sharedDep)) {
85
- config.optimizeDeps.include.push(sharedDep);
86
- }
87
-
88
83
  if (!config.server) config.server = {};
89
84
  if (!config.server.fs) config.server.fs = {};
90
85
  if (config.server.fs.strict === undefined) {
@@ -4,18 +4,18 @@ import { MeshBVH } from 'three-mesh-bvh';
4
4
  // Modified according to https://github.com/gkjohnson/three-mesh-bvh/issues/636#issuecomment-2209571751
5
5
  import { WorkerBase } from "three-mesh-bvh/src/workers/utils/WorkerBase.js";
6
6
 
7
- // Use Vite's ?worker import to get a Worker constructor that works correctly
8
- // in both dev (raw-served) and optimized (pre-bundled) contexts.
9
- // The previous `new URL('...', import.meta.url)` pattern broke when the file
10
- // was pre-bundled because the bundler resolved the URL relative to the source
11
- // file path rather than as a bare module specifier.
12
- import GenerateBVHWorker from 'three-mesh-bvh/src/workers/generateMeshBVH.worker.js?worker';
13
-
14
-
15
7
  export class GenerateMeshBVHWorker extends WorkerBase {
16
8
 
17
9
  constructor() {
18
- super(new GenerateBVHWorker());
10
+ // Worker loading: we use `new URL(specifier, import.meta.url)` + `new Worker(url)`.
11
+ // We can NOT use the Vite `?worker` import suffix (`import W from '...?worker'`) because
12
+ // that breaks pre-bundling: the ?worker query is a Vite-specific convention that doesn't
13
+ // survive the optimizer, and the issue was closed as NOT_PLANNED (vitejs/vite#10837).
14
+ // The `new URL()` pattern works in Vite 8+ thanks to PR #21434 which correctly rebases
15
+ // relative URL paths inside pre-bundled dependencies. This lets us keep three-mesh-bvh
16
+ // in optimizeDeps (no exclude needed), avoiding duplicate three.js instances.
17
+ // https://linear.app/needle/issue/NE-6572
18
+ super(new Worker(new URL('three-mesh-bvh/src/workers/generateMeshBVH.worker.js', import.meta.url), { type: 'module' }));
19
19
  this.name = 'GenerateMeshBVHWorker';
20
20
 
21
21
  }