create-babylonjs 9.13.0 ā 9.15.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.
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateGitignore = generateGitignore;
|
|
4
|
+
function generateGitignore(_options) {
|
|
5
|
+
return `# Dependencies
|
|
6
|
+
node_modules/
|
|
7
|
+
|
|
8
|
+
# Build output
|
|
9
|
+
dist/
|
|
10
|
+
|
|
11
|
+
# Editor directories and files
|
|
12
|
+
.idea/
|
|
13
|
+
|
|
14
|
+
# OS files
|
|
15
|
+
.DS_Store
|
|
16
|
+
Thumbs.db
|
|
17
|
+
|
|
18
|
+
# TypeScript
|
|
19
|
+
*.tsbuildinfo
|
|
20
|
+
`;
|
|
21
|
+
}
|
|
@@ -4,17 +4,15 @@ exports.generateIndexHtml = generateIndexHtml;
|
|
|
4
4
|
function generateIndexHtml(options) {
|
|
5
5
|
const { bundler, moduleFormat } = options;
|
|
6
6
|
const styles = `
|
|
7
|
-
|
|
8
|
-
overflow: hidden;
|
|
9
|
-
width: 100%;
|
|
10
|
-
height: 100%;
|
|
7
|
+
body {
|
|
11
8
|
margin: 0;
|
|
12
9
|
padding: 0;
|
|
13
10
|
}
|
|
14
11
|
|
|
15
12
|
#renderCanvas {
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
display: block;
|
|
14
|
+
width: 100dvw;
|
|
15
|
+
height: 100dvh;
|
|
18
16
|
touch-action: none;
|
|
19
17
|
}`;
|
|
20
18
|
// CDN-only (no bundler, UMD)
|
|
@@ -39,13 +37,28 @@ function generateIndexHtml(options) {
|
|
|
39
37
|
const createScene = async function () {
|
|
40
38
|
const scene = new BABYLON.Scene(engine);
|
|
41
39
|
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
try {
|
|
41
|
+
// Load a glTF model
|
|
42
|
+
await BABYLON.AppendSceneAsync("https://assets.babylonjs.com/meshes/boombox.glb", scene);
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
// Create a default camera, and event caught by the controls will call preventdefault(),
|
|
45
|
+
// such as wheel event
|
|
46
|
+
scene.createDefaultCamera(true, true, true);
|
|
47
|
+
// Rotate the camera to face the front of the model
|
|
48
|
+
scene.activeCamera.alpha += Math.PI;
|
|
49
|
+
} catch {
|
|
50
|
+
// Fallback: when loading fails
|
|
51
|
+
// Create a default box mesh
|
|
52
|
+
BABYLON.CreateBox("box", {}, scene);
|
|
53
|
+
|
|
54
|
+
scene.createDefaultCamera(true, true, true);
|
|
55
|
+
const camera = scene.activeCamera;
|
|
56
|
+
camera.setPosition(new BABYLON.Vector3(3, 3, 3));
|
|
57
|
+
camera.setTarget(new BABYLON.Vector3(0, 0, 0));
|
|
58
|
+
|
|
59
|
+
// Create a default light for the scene
|
|
60
|
+
scene.createDefaultLight(true);
|
|
61
|
+
}
|
|
49
62
|
|
|
50
63
|
// Create a default environment (skybox + ground + environment lighting)
|
|
51
64
|
scene.createDefaultEnvironment({
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateSceneCode = generateSceneCode;
|
|
4
|
-
const GLTF_MODEL_URL = "https://assets.babylonjs.com/meshes/boombox.glb";
|
|
5
4
|
// ES6 scene code ā tree-shakeable imports
|
|
6
5
|
function es6Scene(language) {
|
|
7
6
|
const canvasCast = language === "ts" ? " as HTMLCanvasElement" : "";
|
|
8
7
|
const arcCamImport = language === "ts" ? '\nimport { ArcRotateCamera } from "@babylonjs/core/Cameras/arcRotateCamera";' : "";
|
|
9
|
-
const
|
|
8
|
+
const cameraCast = language === "ts" ? " as ArcRotateCamera" : "";
|
|
10
9
|
return `import { Engine } from "@babylonjs/core/Engines/engine";
|
|
11
10
|
import { Scene } from "@babylonjs/core/scene";
|
|
12
|
-
import { AppendSceneAsync } from "@babylonjs/core/Loading/sceneLoader"
|
|
11
|
+
import { AppendSceneAsync } from "@babylonjs/core/Loading/sceneLoader";
|
|
12
|
+
import { CreateBox } from "@babylonjs/core/Meshes/Builders/boxBuilder";${arcCamImport}
|
|
13
|
+
import { Vector3 } from "@babylonjs/core/Maths/math.vector";
|
|
13
14
|
|
|
14
15
|
// Side-effect imports: these register plugins and augment prototypes at load time
|
|
15
16
|
import "@babylonjs/core/Loading/loadingScreen";
|
|
@@ -22,25 +23,40 @@ import "@babylonjs/loaders/glTF";
|
|
|
22
23
|
const canvas = document.getElementById("renderCanvas")${canvasCast};
|
|
23
24
|
const engine = new Engine(canvas, true);
|
|
24
25
|
|
|
25
|
-
const createScene = async () => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
};
|
|
26
|
+
const createScene = async () => {
|
|
27
|
+
const scene = new Scene(engine);
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
// Load a glTF model
|
|
31
|
+
await AppendSceneAsync("https://assets.babylonjs.com/meshes/boombox.glb", scene);
|
|
32
|
+
|
|
33
|
+
// Create a default camera, and event caught by the controls will call preventdefault(),
|
|
34
|
+
// such as wheel event
|
|
35
|
+
scene.createDefaultCamera(true, true, true);
|
|
36
|
+
// Rotate the camera to face the front of the model
|
|
37
|
+
(scene.activeCamera${cameraCast}).alpha += Math.PI;
|
|
38
|
+
} catch {
|
|
39
|
+
// Fallback: when loading fails
|
|
40
|
+
// Create a default box mesh
|
|
41
|
+
CreateBox("box", {}, scene);
|
|
42
|
+
|
|
43
|
+
scene.createDefaultCamera(true, true, true);
|
|
44
|
+
const camera = scene.activeCamera${cameraCast};
|
|
45
|
+
camera.setPosition(new Vector3(3, 3, 3));
|
|
46
|
+
camera.setTarget(new Vector3(0, 0, 0));
|
|
47
|
+
|
|
48
|
+
// Create a default light for the scene
|
|
49
|
+
scene.createDefaultLight(true);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Create a default environment (skybox + ground + environment lighting)
|
|
53
|
+
scene.createDefaultEnvironment({
|
|
54
|
+
createGround: true,
|
|
55
|
+
createSkybox: true,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return scene;
|
|
59
|
+
};
|
|
44
60
|
|
|
45
61
|
createScene().then((scene) => {
|
|
46
62
|
engine.runRenderLoop(() => {
|
|
@@ -65,13 +81,28 @@ const engine = new BABYLON.Engine(canvas, true);
|
|
|
65
81
|
const createScene = async (): Promise<BABYLON.Scene> => {
|
|
66
82
|
const scene = new BABYLON.Scene(engine);
|
|
67
83
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
84
|
+
try {
|
|
85
|
+
// Load a glTF model
|
|
86
|
+
await BABYLON.AppendSceneAsync("https://assets.babylonjs.com/meshes/boombox.glb", scene);
|
|
87
|
+
|
|
88
|
+
// Create a default camera, and event caught by the controls will call preventdefault(),
|
|
89
|
+
// such as wheel event
|
|
90
|
+
scene.createDefaultCamera(true, true, true);
|
|
91
|
+
// Rotate the camera to face the front of the model
|
|
92
|
+
(scene.activeCamera as BABYLON.ArcRotateCamera).alpha += Math.PI;
|
|
93
|
+
} catch {
|
|
94
|
+
// Fallback: when loading fails
|
|
95
|
+
// Create a default box mesh
|
|
96
|
+
BABYLON.CreateBox("box", {}, scene);
|
|
97
|
+
|
|
98
|
+
scene.createDefaultCamera(true, true, true);
|
|
99
|
+
const camera = scene.activeCamera as BABYLON.ArcRotateCamera;
|
|
100
|
+
camera.setPosition(new BABYLON.Vector3(3, 3, 3));
|
|
101
|
+
camera.setTarget(new BABYLON.Vector3(0, 0, 0));
|
|
102
|
+
|
|
103
|
+
// Create a default light for the scene
|
|
104
|
+
scene.createDefaultLight(true);
|
|
105
|
+
}
|
|
75
106
|
|
|
76
107
|
// Create a default environment (skybox + ground + environment lighting)
|
|
77
108
|
scene.createDefaultEnvironment({
|
|
@@ -104,13 +135,28 @@ const engine = new BABYLON.Engine(canvas, true);
|
|
|
104
135
|
const createScene = async () => {
|
|
105
136
|
const scene = new BABYLON.Scene(engine);
|
|
106
137
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
138
|
+
try {
|
|
139
|
+
// Load a glTF model
|
|
140
|
+
await BABYLON.AppendSceneAsync("https://assets.babylonjs.com/meshes/boombox.glb", scene);
|
|
141
|
+
|
|
142
|
+
// Create a default camera, and event caught by the controls will call preventdefault(),
|
|
143
|
+
// such as wheel event
|
|
144
|
+
scene.createDefaultCamera(true, true, true);
|
|
145
|
+
// Rotate the camera to face the front of the model
|
|
146
|
+
scene.activeCamera.alpha += Math.PI;
|
|
147
|
+
} catch {
|
|
148
|
+
// Fallback: when loading fails
|
|
149
|
+
// Create a default box mesh
|
|
150
|
+
BABYLON.CreateBox("box", {}, scene);
|
|
151
|
+
|
|
152
|
+
scene.createDefaultCamera(true, true, true);
|
|
153
|
+
const camera = scene.activeCamera;
|
|
154
|
+
camera.setPosition(new BABYLON.Vector3(3, 3, 3));
|
|
155
|
+
camera.setTarget(new BABYLON.Vector3(0, 0, 0));
|
|
156
|
+
|
|
157
|
+
// Create a default light for the scene
|
|
158
|
+
scene.createDefaultLight(true);
|
|
159
|
+
}
|
|
114
160
|
|
|
115
161
|
// Create a default environment (skybox + ground + environment lighting)
|
|
116
162
|
scene.createDefaultEnvironment({
|
|
@@ -3,23 +3,32 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateTsConfig = generateTsConfig;
|
|
4
4
|
function generateTsConfig(options) {
|
|
5
5
|
const { bundler, moduleFormat } = options;
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
sourceMap: true,
|
|
17
|
-
},
|
|
18
|
-
include: ["src"],
|
|
6
|
+
const types = [];
|
|
7
|
+
const compilerOptions = {
|
|
8
|
+
target: "ES2020",
|
|
9
|
+
module: bundler === "vite" ? "ESNext" : "ES2020",
|
|
10
|
+
moduleResolution: bundler === "vite" ? "bundler" : "node",
|
|
11
|
+
strict: true,
|
|
12
|
+
esModuleInterop: true,
|
|
13
|
+
skipLibCheck: true,
|
|
14
|
+
forceConsistentCasingInFileNames: true,
|
|
15
|
+
sourceMap: true,
|
|
19
16
|
};
|
|
17
|
+
if (bundler === "vite") {
|
|
18
|
+
// Vite handles the actual bundling, so TypeScript only needs to type-check without emitting output
|
|
19
|
+
compilerOptions.noEmit = true;
|
|
20
|
+
// Add Vite client type declarations (e.g., import.meta.env, asset imports)
|
|
21
|
+
types.push("vite/client");
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
compilerOptions.outDir = "./dist";
|
|
25
|
+
}
|
|
20
26
|
// UMD packages ship their own typings via the `babylonjs` package
|
|
21
27
|
if (moduleFormat === "umd") {
|
|
22
|
-
|
|
28
|
+
types.push("babylonjs");
|
|
29
|
+
}
|
|
30
|
+
if (types.length > 0) {
|
|
31
|
+
compilerOptions.types = types;
|
|
23
32
|
}
|
|
24
|
-
return JSON.stringify(
|
|
33
|
+
return JSON.stringify({ compilerOptions, include: ["src"] }, null, 2) + "\n";
|
|
25
34
|
}
|
package/dist/index.js
CHANGED
|
@@ -12,6 +12,7 @@ const indexHtml_1 = require("./generators/indexHtml");
|
|
|
12
12
|
const sceneCode_1 = require("./generators/sceneCode");
|
|
13
13
|
const bundlerConfig_1 = require("./generators/bundlerConfig");
|
|
14
14
|
const tsConfig_1 = require("./generators/tsConfig");
|
|
15
|
+
const gitignore_1 = require("./generators/gitignore");
|
|
15
16
|
async function main() {
|
|
16
17
|
console.log("\nšļø Create Babylon.js Project\n");
|
|
17
18
|
const response = await (0, prompts_1.default)([
|
|
@@ -96,6 +97,8 @@ async function main() {
|
|
|
96
97
|
}
|
|
97
98
|
function scaffoldProject(targetDir, options) {
|
|
98
99
|
fs_1.default.mkdirSync(targetDir, { recursive: true });
|
|
100
|
+
// All projects get a .gitignore
|
|
101
|
+
writeFile(targetDir, ".gitignore", (0, gitignore_1.generateGitignore)(options));
|
|
99
102
|
if (options.bundler === "none") {
|
|
100
103
|
// CDN-only: just an HTML file
|
|
101
104
|
writeFile(targetDir, "index.html", (0, indexHtml_1.generateIndexHtml)(options));
|
package/package.json
CHANGED