Needle Engine

Changes between version 3.40.0-alpha.2 and 3.40.0-alpha.3
Files changed (2) hide show
  1. plugins/vite/config.js +26 -1
  2. src/engine/engine_three_utils.ts +8 -2
plugins/vite/config.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { existsSync, readFileSync } from 'fs';
2
+ import path from 'path';
2
3
 
3
4
  let didLogCanNotFindConfig = false;
4
5
 
@@ -71,5 +72,29 @@
71
72
  /** @returns the fullpath of the build */
72
73
  export function getOutputDirectory() {
73
74
  const projectConfig = tryLoadProjectConfig();
74
- return process.cwd() + "/" + (projectConfig?.buildDirectory || "dist");
75
+ if (projectConfig?.buildDirectory) {
76
+ return path.join(process.cwd(), projectConfig.buildDirectory);
77
+ }
78
+
79
+ // if it's a sveltekit project
80
+ try {
81
+ const sveltekitConfig = path.join(process.cwd(), 'svelte.config.js');
82
+ if (existsSync(sveltekitConfig)) {
83
+ const regex = /outDir\s?:\s?\"(.*?)\"/g;
84
+ const content = readFileSync(sveltekitConfig, 'utf8');
85
+ const match = regex.exec(content);
86
+ if (match) {
87
+ return path.join(process.cwd(), match[1]);
88
+ }
89
+ else {
90
+ // default output directory
91
+ return path.join(process.cwd(), 'build');
92
+ }
93
+ }
94
+ }
95
+ catch {
96
+ // ignore
97
+ }
98
+
99
+ return path.join(process.cwd(), 'dist');
75
100
  }
src/engine/engine_three_utils.ts CHANGED
@@ -476,8 +476,12 @@
476
476
 
477
477
 
478
478
 
479
+ function isMesh(obj: Object3D): obj is Mesh {
480
+ const type = obj.type;
481
+ // Note: we don't use the instanceof check here because it's unreliable in certain minification scenarios where it returns false
482
+ return type === "Mesh" || type === "SkinnedMesh";
483
+ }
479
484
 
480
-
481
485
  export function getBoundingBox(objects: Object3D[], ignore: Object3D[] = []): Box3 {
482
486
  const box = new Box3();
483
487
  box.makeEmpty();
@@ -497,7 +501,9 @@
497
501
  // // Ignore shadow catcher geometry
498
502
  if ((obj as Mesh).material instanceof ShadowMaterial) allowExpanding = false;
499
503
  // ONLY fit meshes
500
- if (!(obj instanceof Mesh)) allowExpanding = false;
504
+ if (!(isMesh(obj))) {
505
+ allowExpanding = false;
506
+ }
501
507
  // Ignore things parented to the camera + ignore the camera
502
508
  if (ignore?.includes(obj)) return;
503
509
  // We don't want to fit UI objects