create-shallot 0.4.0 → 0.5.1
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.
- package/index.ts +42 -13
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -79,6 +79,8 @@ writeFileSync(
|
|
|
79
79
|
target: "ESNext",
|
|
80
80
|
module: "ESNext",
|
|
81
81
|
moduleResolution: "bundler",
|
|
82
|
+
lib: ["ESNext", "DOM", "DOM.Iterable"],
|
|
83
|
+
types: ["@webgpu/types", "vite/client"],
|
|
82
84
|
strict: true,
|
|
83
85
|
noEmit: true,
|
|
84
86
|
skipLibCheck: true,
|
|
@@ -97,11 +99,11 @@ writeFileSync(
|
|
|
97
99
|
<head>
|
|
98
100
|
<meta charset="UTF-8" />
|
|
99
101
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
100
|
-
<link rel="icon" type="image/svg+xml" href="
|
|
102
|
+
<link rel="icon" type="image/svg+xml" href="./icon.svg" />
|
|
101
103
|
<title>${name}</title>
|
|
102
104
|
<style>
|
|
103
105
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
104
|
-
body { background: #
|
|
106
|
+
body { background: #0c0a09; overflow: hidden; }
|
|
105
107
|
canvas { display: block; width: 100vw; height: 100vh; }
|
|
106
108
|
</style>
|
|
107
109
|
</head>
|
|
@@ -118,6 +120,7 @@ writeFileSync(
|
|
|
118
120
|
`import { defineConfig } from "vite";
|
|
119
121
|
|
|
120
122
|
export default defineConfig({
|
|
123
|
+
base: "./",
|
|
121
124
|
server: { port: 3000 },
|
|
122
125
|
build: {
|
|
123
126
|
target: "esnext",
|
|
@@ -130,12 +133,31 @@ export default defineConfig({
|
|
|
130
133
|
|
|
131
134
|
writeFileSync(
|
|
132
135
|
join(dir, "src/lib.ts"),
|
|
133
|
-
`import { type Config } from "@dylanebert/shallot";
|
|
134
|
-
|
|
136
|
+
`import { type Config, Part, quat, type State, type System, Transform } from "@dylanebert/shallot";
|
|
137
|
+
|
|
138
|
+
// A system is plain data: an \`update\` the engine runs each frame. This one spins
|
|
139
|
+
// every Part around Y. It runs in the standalone app but not the editor — \`shallot .\`
|
|
140
|
+
// builds in edit mode, where unannotated systems are skipped, so the cube stays put
|
|
141
|
+
// and editable there. Delete it (and the plugin entry below) for a static scene.
|
|
142
|
+
let angle = 0;
|
|
143
|
+
const SpinSystem: System = {
|
|
144
|
+
group: "simulation",
|
|
145
|
+
update(state: State) {
|
|
146
|
+
angle = (angle + state.time.deltaTime * 45) % 360;
|
|
147
|
+
const q = quat(0, angle, 0);
|
|
148
|
+
for (const eid of state.query([Part, Transform])) {
|
|
149
|
+
Transform.rot.set(eid, q.x, q.y, q.z, q.w);
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
};
|
|
135
153
|
|
|
154
|
+
// The project definition, shared by the standalone app (src/main.ts) and the shallot
|
|
155
|
+
// editor (\`shallot .\`). The default plugins (render, lit surface, orbit camera) stay
|
|
156
|
+
// on; the spin plugin adds our one system. The scene lives here too, so main.ts stays
|
|
157
|
+
// untouched as the project grows.
|
|
136
158
|
export const config: Config = {
|
|
137
|
-
plugins: [
|
|
138
|
-
scene: "
|
|
159
|
+
plugins: [{ name: "spin", systems: [SpinSystem] }],
|
|
160
|
+
scene: "scenes/scene.scene",
|
|
139
161
|
};
|
|
140
162
|
`,
|
|
141
163
|
);
|
|
@@ -145,21 +167,28 @@ writeFileSync(
|
|
|
145
167
|
`import { run } from "@dylanebert/shallot";
|
|
146
168
|
import { config } from "./lib";
|
|
147
169
|
|
|
148
|
-
|
|
170
|
+
// One config source (src/lib.ts) drives both this standalone build and the editor. The camera
|
|
171
|
+
// auto-binds to the page's <canvas>.
|
|
172
|
+
const { dispose } = await run(config);
|
|
149
173
|
|
|
174
|
+
// HMR re-runs this module — dispose the old State + RAF loop or each reload stacks another.
|
|
150
175
|
if (import.meta.hot) {
|
|
151
|
-
import.meta.hot.dispose(() =>
|
|
176
|
+
import.meta.hot.dispose(() => dispose());
|
|
152
177
|
}
|
|
153
178
|
`,
|
|
154
179
|
);
|
|
155
180
|
|
|
156
181
|
writeFileSync(
|
|
157
|
-
join(dir, "public/scenes/
|
|
182
|
+
join(dir, "public/scenes/scene.scene"),
|
|
158
183
|
`<scene>
|
|
159
|
-
<a
|
|
160
|
-
<a
|
|
161
|
-
|
|
162
|
-
|
|
184
|
+
<a ambient-light="color: 0xd0dcec; intensity: 0.5" />
|
|
185
|
+
<a directional-light="direction: -0.4 -1 -0.55; color: 0xfff4e0; intensity: 1.1" />
|
|
186
|
+
|
|
187
|
+
<!-- the camera auto-binds to the page's <canvas>; drag to orbit, scroll to zoom -->
|
|
188
|
+
<a camera sear orbit="distance: 5; yaw: 0.6; pitch: 0.25" transform />
|
|
189
|
+
|
|
190
|
+
<!-- a Part is the engine's drop-in renderable: a mesh (default "cube") wearing a surface (default "default", lit) -->
|
|
191
|
+
<a part transform="pos: 0 0 0" color="rgba: 0.85 0.55 0.35 1" />
|
|
163
192
|
</scene>
|
|
164
193
|
`,
|
|
165
194
|
);
|